编译器错误 C2178

不能使用“specifier”说明符声明“identifier”

声明中使用了 mutable 说明符,但在此上下文中不允许使用说明符。

mutable 说明符仅可应用于类数据成员的名称,不能应用于声明为 conststatic 的名称,也不能应用于引用成员。

示例

以下示例显示了 C2178 是如何发生的,以及如何修复。

// C2178.cpp
// compile with: cl /c /W4 C2178.cpp

class S {
    mutable const int i; // C2178
    // To fix, declare either const or mutable, not both.
};

mutable int x = 4; // C2178
// To fix, remove mutable keyword