mar*_*zzz 0 c++ initialization private
我是这堂课:
class IPianoRoll : public IControl
{
private:
int x, y;
int w = 30 * numStep + 1;
int h = 8 * numSemitones + 1;
int o = 5;
public:
IPianoRoll(IPlugBase* pPlug, int pX, int pY) : IControl(pPlug, IRECT(pX, pY, pX + o + w + o, pY + o + h + o)) {
x = pX;
y = pY;
}
}
Run Code Online (Sandbox Code Playgroud)
但似乎私有变量值比成员初始化列表"更晚"可用.所以o,w和h不符合我的价值观初始化,它需要不同的值.
有没有办法预启动私有变量?
类成员的访问说明符不相关.什么是相关的是它们出现在类的顺序声明.类成员按该顺序初始化.
依赖于类成员的特定初始化顺序是非常危险的,因为错误的重构器可以在头文件中重新排序它们,幸福地不知道源文件依赖于特定的排序.
您还应该注意,读取未初始化变量时的行为是未定义的.