C++ 27 之 初始化列表

c27初始化列表.cpp

cpp 复制代码
#include <iostream>
#include <string.h>
using namespace std;

class Students06{
public:
    int s_a;
    int s_b;
    int s_c;
    Students06(int a, int b, int c){
        s_a = a;
        s_b = b;
        s_c = c;
    }

    // 初始化列表写法1:
    // Students06():s_a(4),s_b(5),s_c(6)
    // {

    // }
    // 初始化列表写法2:
    // Students06(int a, int b, int c) : s_a(a), s_b(b), s_c(c)
    // {

    // }
};


int main()
{
    // 普通写法
    Students06 stu1(1, 2, 3);
    cout << stu1.s_a << endl;
    cout << stu1.s_b << endl;
    cout << stu1.s_c << endl;

    // 初始化列表写法1:
    // Students06 stu1;
    // cout << stu1.s_a << endl;
    // cout << stu1.s_b << endl;
    // cout << stu1.s_c << endl;

    // 初始化列表写法2: 
    // Students06 stu1(7,8,9);
    // cout << stu1.s_a << endl;
    // cout << stu1.s_b << endl;
    // cout << stu1.s_c << endl;


    return 0;
}
相关推荐
好开心啊没烦恼7 分钟前
Python 数据分析:计算,分组统计1,df.groupby()。听故事学知识点怎么这么容易?
开发语言·python·数据挖掘·数据分析·pandas
lljss20201 小时前
Python11中创建虚拟环境、安装 TensorFlow
开发语言·python·tensorflow
山登绝顶我为峰 3(^v^)32 小时前
如何录制带备注的演示文稿(LaTex Beamer + Pympress)
c++·线性代数·算法·计算机·密码学·音视频·latex
Python×CATIA工业智造4 小时前
Frida RPC高级应用:动态模拟执行Android so文件实战指南
开发语言·python·pycharm
十五年专注C++开发5 小时前
CMake基础:条件判断详解
c++·跨平台·cmake·自动化编译
我叫小白菜5 小时前
【Java_EE】单例模式、阻塞队列、线程池、定时器
java·开发语言
狐凄5 小时前
Python实例题:基于 Python 的简单聊天机器人
开发语言·python
weixin_446122466 小时前
JAVA内存区域划分
java·开发语言·redis
悦悦子a啊6 小时前
Python之--基本知识
开发语言·前端·python
QuantumStack7 小时前
【C++ 真题】P1104 生日
开发语言·c++·算法