#include <iostream>
using namespace std;
class person
{
private:
string name;
int age;
public:
person(const string &getname):
name(getname), age(0){ }
void addAge(const string &getname)
{
age++;
}
void getAge(void)
{
cout << endl;
cout << name << " now " << age << " years old";
}
};
int main()
{
person *p;
p = new person("John");
p->addAge("John");
p->addAge("John");
p->addAge("John");
p->getAge(); //3
p = new person("Connor");
p->addAge("Connor");
p->getAge(); //1
*p = person("John");
p->addAge("John");
p->getAge(); //John age start at 1 again????
cout << endl;
return 0;
}
How do I increase John age, after I insert new person???
can anyone help me please.
Thank You