C++ 成员列表初始化
class Person
{
private:
public:
std::string Name;
Person(std::string name):Name(name)//这中写法叫成员列表初始化
{
}
};
等价的写法:
class Person
{
private:
public:
std::string Name;
Person(std::string name)
{
Name = name;
}
};