| | | | | |

Destructor

  • Each declaration calls class constructor
  • Destructor called when object goes out of scope
  • Destructor call is implicit and automatic
//  client code

{ // begin block
  ...
  IntArray A (1000, -1);  
  IntArray B (100);       
  IntArray C;             
  ...
} // end block
    class IntArray
    {
      public:
        IntArray  (size_t sz = 10, int ivalue = 0);
        ~IntArray ();
        // more later
    
      private:
        size_t size_;
        int *  data_;
    }
    
    IntArray::~IntArray ()
    {
      delete [] data_;
    }
    

| | Top of Page | 6. C++ Classes Part 2: Advanced Features - 2 of 22