在一个Code::Blocks v13.12
项目中,我有一个名为的类Drawable
,它有一个名为rotation
.
我注意到明确声明rotation
insideDrawable
的默认构造函数会触发以下警告:
'Drawable::rotation' 应该在成员初始化列表中初始化 [-Weffc++]
但是,rotation
在其定义旁边显式声明并不能做到这一点。
我想知道的是,为什么会这样:
Drawable() {
rotation = 0.f;
}
给我一个成员初始化警告,而这个:
class Drawable
{
...
float rotation = 0.f;
...
}
还有这个:
Drawable() : rotation(0.f) {}
编译没有抱怨?