// demonstrates destructor with object cotnaining array // Mikhail Nesterenko // 11/2/2014 class MyClass{ public: MyClass(int); // constructor ~MyClass(); // destructor private: int *d; int size; }; MyClass::MyClass(int n){ size=n; d = new int[size]; for(int i=0; i< size; ++i) d[i]=0; } MyClass::~MyClass(){ delete [] d; } // standalone function using an object of MyClass void otherfunc(){ MyCliass myobj(5); // constructor allocates dynamic array } // destructor is implicitly invoked here int main(){ otherfunc(); }