MyClass::MyClass(const MyClass & rhs) { itsAge = new int; itsWeight = new int; *itsAge = rhs.GetAge(); *itsWeight = rhs.GetWeight(); }
int main() { MyClass myObject; std::cout << "myObject's age: " << myObject.GetAge() << "\n"; std::cout << "Setting myObject to 6...\n"; myObject.SetAge(6); std::cout << "Creating secondObject from myObject\n"; MyClass secondObject(myObject); std::cout << "myObject's age: " << myObject.GetAge() << "\n"; std::cout << "secondObject' age: " << secondObject.GetAge() << "\n"; std::cout << "setting myObject to 7...\n"; myObject.SetAge(7); std::cout << "myObject's age: " << myObject.GetAge() << "\n"; std::cout << "boot's age: " << secondObject.GetAge() << "\n"; getch(); return 0; }