Implementation
Implementation
#include <iostream>
using namespace std;
class MyClass {
public:
MyClass();
MyClass(const MyClass& origClass);
~MyClass();
void SetDataObj(const int setVal) {
*dataObj = setVal;
}
int GetDataObj() const {
return *dataObj;
}
private:
int* dataObj;
};
MyClass::MyClass() {
cout << "Constructor called." << endl;
dataObj = new int;
*dataObj = 0;
return;
}
MyClass::MyClass(const MyClass& origClass) {
cout << "Copy constructor called." << endl;
dataObj = new int;
*dataObj = *(origClass.dataObj);
return;
}
MyClass::~MyClass() {
cout << "Destructor called." << endl;
delete dataObj;
return;
}
void SomeFunction(MyClass localObj) {
return;
}
int main() {
MyClass tempClassObj;
tempClassObj.SetDataObj(9);
cout << "Before: " << tempClassObj.GetDataObj() << endl;
SomeFunction(tempClassObj);
cout << "After: " << tempClassObj.GetDataObj() << endl;
return 0;
}