这个问题与此处随后提出的问题密切相关。
Stroustrup 在这里描述了定义类内常量的方法。
当我遵循 Stroustrup 的方法时,我看到了预期的结果。但是,在 Visual Studio 2010 中,调试器无法解析static const
该类范围内的类成员。这就是我的意思:
#include <iostream>
class Foo {
public:
static const int A = 50;
char arr[A];
void showA();
};
void Foo::showA() {
std::cout << "showA = " << A << "\n";
}
int main() {
Foo f;
f.showA();
}
当调试器在 showA() 中时,“watch”窗口会报告:
Error: Symbol "Foo::A" not found
我想强调一下,该程序确实按预期运行,即输出为:
showA = 50
程序返回 0。
其他人可以用 Visual Studio 2010 重现这个吗?这是调试器中的错误吗?