// z6.6.1-copy.cc // #include using namespace std; class MyClass { public: MyClass(); ~MyClass(); // Set member value dataObj void SetDataObj(const int setVal) { *dataObj = setVal; } // Return member value dataObj int GetDataObj() const { return *dataObj; } private: int* dataObj;// Data member }; // Default constructor MyClass::MyClass() { cout << "Constructor called." << endl; dataObj = new int; // Allocate mem for data *dataObj = -1; } // Destructor MyClass::~MyClass() { cout << "Destructor called." << endl; delete dataObj; } void SomeFunction(MyClass localObj) { // Do something with localObj } int main() { MyClass tempClassObj; // Create object of type MyClass // Set and print data member value tempClassObj.SetDataObj(9); cout << "Before: " << tempClassObj.GetDataObj() << endl; // Calls SomeFunction(), tempClassObj is passed by value SomeFunction(tempClassObj); // Print data member value cout << "After: " << tempClassObj.GetDataObj() << endl; return 0; }