如下代码,运行结果为:
#include<iostream>
using namespace std;
class Person
{
public:
Person()
{
}
Person(int age)
{
cout << "带参构造函数" << endl;
_age = age;
}
~Person()
{
cout << "析构函数" << endl;
}
void Print()
{
cout << "年龄: " << _age << endl;
}
private:
int _age;
};
int main()
{
Person p1(10);
p1.Print();
return 0;
}
现在我们给Person类添加一个成员变量int *height