#include<iostream>
using namespace std;
//初始化列表:用来初始化属性
//语法:构造函数:属性1(值1),属性2(值2)....(){}
class people
{
public:
int m_A;
int m_B;
int m_C;
//传统初始化操作
/*people(int a, int b, int c)
{
m_A = a;
m_B = b;
m_C = c;
}*/
//初始化列表初始化属性
people(int a,int b,int c) :m_A(a), m_B(b), m_C(c)
{
}
};
void test08()
{
//people p(10, 20, 30);
people p(30,20,10);
cout << "m_A:" << p.m_A << endl;
cout << "m_B:" << p.m_B << endl;
cout << "m_C:" << p.m_C << endl;
}
int main()
{
test08();
system("pause");
return 0;
}
网友评论