Advertisement

创建列表和类对象作为该类的成员

阅读量:

初始化列表


复制代码
 #include<iostream>

    
 //初始化列表
    
 using namespace std;
    
 class Person
    
 {
    
 public:
    
 	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(30,20,10);
    
  
    
 	cout << p.m_A << endl;
    
 	cout << p.m_B << endl;
    
 	cout << p.m_C << endl;
    
  
    
 }
    
 int main()
    
 {
    
  
    
 	test01();
    
 	system("pause");
    
 	return 0;
    
 }
    
    
    
    

![](https://ad.itadn.com/c/weblog/blog-img

全部评论 (0)

还没有任何评论哟~