编程语言
首页 > 编程语言> > C++初始化列表

C++初始化列表

作者:互联网

语法:构造函数():属性1(值1),属性2(值2),…{}

#include<iostream>
using namespace std;

class WLM
{
public:

    WLM(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 test()
{
    WLM zjy(10,20,30);
    cout << "m_a =" << zjy.m_a << endl;
    cout << "m_b =" << zjy.m_b << endl;
    cout << "m_c =" << zjy.m_c << endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
    test();
    
    system("pause");
    return 0;
}

标签:std,初始化,include,int,C++,列表,WLM,构造函数,属性
来源: https://www.cnblogs.com/ZJY-WLM/p/16524735.html