Пример #1
0
 DogHouse(const DogHouse& dh)
   : p(dh.p),
     houseName("copy-constructed " + 
       dh.houseName) {
   p->attach();
   cout << "DogHouse copy-constructor: "
        << *this << endl;
 }
Пример #2
0
 DogHouse& operator=(const DogHouse& dh) {
   // Check for self-assignment:
   if(&dh != this) {
     houseName = dh.houseName + " assigned";
     // Clean up what you're using first:
     p->detach();
     p = dh.p; // Like copy-constructor
     p->attach();
   }
   cout << "DogHouse operator= : "
        << *this << endl;
   return *this;
 }