#include <iostream>
class MyClass
{
public:
MyClass() {
itsAge = 2;
}
~MyClass() {}
int GetAge() const {
return itsAge;
}
void SetAge(int age) {
itsAge = age;
}
private:
int itsAge;
};
int main()
{
MyClass * myObject = new MyClass;
std::cout << "myObject is " << myObject->GetAge() << " years old\n";
myObject->SetAge(5);
std::cout << "myObject is " << myObject->GetAge() << " years old\n";
delete myObject;
return 0;
}
|