c++类的常对象未初始化

img

img

img


这个问题该怎么进行解决呢,说是未初始常对象,请哪位热心人士来帮忙指点迷津

const关键字了解一下, 被const常量修饰的变量,会默认成常量,要么默认构造函数自己初始化,要么你要做初始化。
擦擦,你声明类为const,类内一个成员变量又定义成mutable,这两个关键字反义啊。

你试着去掉 mutable,他会默认调用构造函数,是可以的
或者你就不要用const。。。

我的理解是const和mutable是反义的。

如果你定义const Person变量而不提供初始值,那么Person类必须有默认构造函数。

From the C++03 Standard
8.5 [dcl.init] paragraph 9

If no initializer is specified for an object, and the object is of (possibly cv-qualified) non-POD class type (or array thereof), the object shall be default-initialized; if the object is of const-qualified type, the underlying class type shall have a user-declared default constructor.

可能是提示你最好有一个构造函数来初始化m_A