初始化列表
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 class Person 5 { 6 public: 7 Person() 8 { 9 cout << "无参构造" << endl; 10 } 11 Person(int a,int b,int c):A(a),B(b),C(c){} 12 void PrintPerson() 13 { 14 cout << "A:" << A << endl; 15 cout << "B:" << B << endl; 16 cout << "C:" << C << endl; 17 } 18 private: 19 int A; 20 int B; 21 int C; 22 23 }; 24 25 int main() 26 { 27 Person person(1, 2, 3); 28 person.PrintPerson(); 29 return 0; 30 }
道阻且长,行则将至