1.包含初始化参数的默认构造函数,并使用初始化列表设置成员
#include <iostream>
#include <string.h>
using namespace std;
class Human
{
private:
int age;
string name;
public:
Human(string humansName = "Adam", int humansAge = 25)
:name(humansName), age(humansAge)
{
cout << "Constructed a human called " << name;
cout << ", " << age << " years old" << endl;
}
};
int main()
{
Human adam;
Human eve("Eve", 18);
return 0;
}
2.析构函数再对象被销毁时被自动调用
3. Human *tom=new human()指向对象的指针,才使用->,其余情况用.