Пример #1
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;
 }
Пример #2
0
 // Decrement refcount, conditionally destroy
 ~DogHouse() {
   cout << "DogHouse destructor: " 
        << *this << endl;
   p->detach(); 
 }