我在C++中有以下类:
class a {
const int b[2];
// other stuff follows
// and here's the constructor
a(void);
}
Run Code Online (Sandbox Code Playgroud)
问题是,如何在初始化列表中初始化b,因为我无法在构造函数体内初始化它,因为b是const?
这不起作用:
a::a(void) :
b([2,3])
{
// other initialization stuff
}
Run Code Online (Sandbox Code Playgroud)
编辑:这个例子就是我可以b为不同的实例设置不同的值,但是已知这些值在实例的生命周期内是不变的.