zoukankan      html  css  js  c++  java
  • (C++核心编程 )初始化列表

    #include <iostream>
    using namespace std;
    #include <string>
    
    
    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) {}
    void PrintPerson() {
        cout << "mA:" << m_A << endl;
        cout << "mB:" << m_B << endl;
        cout << "mC:" << m_C << endl;
    }
    private:
        int m_A;
        int m_B;
        int m_C;
    };
    int main()
    {
        Person p(1, 2, 3);
        p.PrintPerson();
    
    
        system("pause");
        return 0;
    
    }
  • 相关阅读:
    没有上司的舞会
    邮票面值设计
    小木棍
    简单的试炼
    区间质数
    加工生产调度
    泥泞的道路
    总数统计
    中庸之道

  • 原文地址:https://www.cnblogs.com/keepma/p/15553821.html
Copyright © 2011-2022 走看看