常变化被初始化(在初始化列表中)

源程序:

#include <iostream>
using namespace std;

class A
{
private:
int x;
const int y;
public:
A(int a, int b):x(a),y(b) //常变量必须在初始化列表中被初始化
{
}
void show()
{
cout << "x=" << x << ", y=" << y << endl;
}
};
int main()
{
A m(4, 5);
m.show();
return 1;
}

原文地址:https://www.cnblogs.com/duanqibo/p/15614444.html