/*
* 初始化列表
作用:c++提供了初始化列表语法,用来初始化属性
语法:构造函数():属性1(值1),属性2(值2)...{};
*/
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
传统方式初始化
//Person(int a, int b, int c)
//{
// m_A = a;
// m_B = b;
// m_C = c;
//}
//初始化列表方式初始化
Person(int a, int b, int c) :m_A(a), m_B(b), m_C(c) {};
void printPerson()
{
cout << "m_A:" << m_A << endl;
cout << "m_B:" << m_B << endl;
cout << "m_C:" << m_C << endl;
}
private:
int m_A;
int m_B;
int m_C;
};
int main()
{
Person p(10, 20, 30);
p.printPerson();
system("pause");
return 0;
}
07-01
2946
10-18
1246
11-29
2031
11-24
2684
03-04
38万+
11-29
1173