类的初始化列表

#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) {

	}
	int m_A;
	int m_B;
	int m_C;
};
void test01() {
	Person p(10, 20, 30);
	//Person p;
	cout << p.m_A << endl;
	cout << p.m_B << endl;
	cout << p.m_C << endl;
}
int main() {
	test01();
	return 0;
}

版权声明:本文为m0_47642376原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。