Guest User

Untitled

a guest
May 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. class A {
  2.            
  3.       public:
  4.       static int count;   // Maybe set this to static?
  5.      
  6.          
  7.       A() {                // "2) It doesn't "manage" any pointers - nor does it take pointers as arguments." ... so no arguments here...?
  8.        count++;           // "The two constructors need to increase the count of objects"
  9.       }
  10.      
  11.       A(A &p)
  12.       {
  13.         count++;          // "The two constructors need to increase the count of objects"
  14.       }
  15.      
  16.       A& operator=(const A &p)
  17.       {
  18.         if (&p != this) {
  19.             // ?? count is static, so just increase it?
  20.             count++;
  21.         }
  22.         return *this;
  23.       }
  24.      
  25.       ~A() {
  26.         count--;           // "the destructor needs to decrease [the count of objects]."
  27.         if (count == 0)
  28.         {
  29.           // ?? No pointers taken as an argument, so I have nothing to delete
  30.         }
  31.       }
  32.    
  33.     };
  34.  
  35.     int A::count = 0;
Add Comment
Please, Sign In to add comment