为什么static const
成员不能存在于本地类中的原因是什么?这似乎是一个相当愚蠢的限制。
例子:
void foo() {
struct bar {
int baz() { return 0; } // allowed
static const int qux = 0; // not allowed?!?
};
}
struct non_local_bar {
int baz() { return 0; } // allowed
static const int qux = 0; // allowed
};
引用标准(9.8.4):
本地类不应具有静态数据成员。