// This program illustrates the use of constructors and // destructors in the allocation and deallocation of // memory. #include #include using namespace std; class InvItem { private: string *description; int units; public: InvItem(string descr, int number) //constructor { description = new string; *description = descr; units = number; } ~InvItem() //destructor { delete description; } string *getDesc() { return description; } int getUnits() { return units; } }; int main() { // Use the constructor to create an object. InvItem stock("Wrench", 20); // Print the object's details. cout << "Item description: " << *stock.getDesc() << endl; cout << "Units on hand: " << stock.getUnits() << endl; return 0; }