-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththis.cpp
More file actions
55 lines (36 loc) · 711 Bytes
/
this.cpp
File metadata and controls
55 lines (36 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <string>
using namespace std;
class Person;
class Pet
{
string name;
Person* owner;
public:
Pet (string name_, Person* owner_) : name(name_), owner(owner_) {}
void collar ();
string getName () { return name; }
};
class Person
{
string name;
Pet pet;
public:
Person (string name_, string petName_) : name(name_), pet(petName_, this) {}
void call ()
{
cout << pet.getName() << " get over here buddy!" << endl;
}
string getName () { return name; }
};
void Pet::collar()
{
cout << "I'm " << name << " and my owner is " << owner->getName() << endl;
}
int main ()
{
Person me ("George", "Azor");
me.call();
Pet lost ("Rex", &me);
lost.collar();
}