-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyingWithPointers.cpp
67 lines (67 loc) · 1.65 KB
/
CopyingWithPointers.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
//#include <string>
//#include <iostream>
//using namespace std;
//class Dog
//{
// string nm;
//public:
// Dog(const string& name):nm(name){
// cout<<"Creating Dog"<<*this<<endl;
//
// }
// Dog(const Dog* dp,const string &msg):nm(dp->nm+msg){
//cout<<"copied dog"<<*this<<"from"<<*dp<<endl;
// }
// ~Dog(){
// cout<<"deleting Dog"<<*this<<endl;
// }
// void rename(const string& newName){
// nm=newName;
// cout<<"Dog renamed to "<<*this<<endl;
// }
// friend ostream& operator<<(ostream& os,const Dog&d);
//
//};
//ostream& operator<<(ostream& os,const Dog&d)
//{
// return os<<"["<<d.nm<<"]";
//}
//class DogHouse{
// Dog*p;
// string houseName;
//public:
// DogHouse(Dog*dog,const string &house)
// :p(dog),houseName(house){}
// DogHouse(const DogHouse&dh):p(new Dog(dh.p,"copy-constructed!")),houseName(dh.houseName+" copy-constructed"){}
// DogHouse& operator=(const DogHouse&dh){
// if (&dh!=this)
// {
// p=new Dog(dh.p,"assigned");
// houseName=dh.houseName+"assigned";
// }
// return *this;
// }
// void renameHouse(const string&newName)
// {
// houseName=newName;
// }
// Dog*getDog()const {return p;}
// ~DogHouse(){delete p;}
// friend ostream& operator<<(ostream& os,const DogHouse&dh){
// return os<<"["<<dh.houseName<<"] contains"<<*dh.p;
// }
//
//};
//int main(){
// DogHouse fidos(new Dog("Fidos"),"FidosHouse");
// cout<<fidos<<endl;
// DogHouse fidos2=fidos;
// cout<<fidos2<<endl;
// fidos2.getDog()->rename("spot");
// fidos2.renameHouse("spotHouse");
// cout<<fidos2<<endl;
// fidos=fidos2;
// cout<<fidos<<endl;
// fidos.getDog()->rename("Max");
// fidos2.renameHouse("MaxHouse");
//}