// z6.7.1-assign.cc // #include using namespace std; class MyClass { public: MyClass(); ~MyClass(); void SetDataObj(const int i) {*dataObj = i;} int GetDataObj() const {return *dataObj;} private: int* dataObj; }; MyClass::MyClass() { cout << "Constructor called." << endl; dataObj = new int; // Allocate data object *dataObj = 0; } MyClass::~MyClass() { cout << "Destructor called." << endl; delete dataObj; } int main() { MyClass classObj1; MyClass classObj2; classObj1.SetDataObj(9); classObj2 = classObj1; cout << "classObj2: "; cout << classObj2.GetDataObj() << endl; return 0; }