【发布时间】:2016-01-01 15:45:49
【问题描述】:
我在类中有一个私有静态 const 成员,在类实现中我有尝试使用此 const 的静态函数,但它给了我错误。
//A.hpp
class A {
static const int X = 1; //<<problem here
// ....
}
我有
//A.cpp
static int DoSomething();
// ....
static int DoSomething {
int n = A::X; //<<problem here
//....
}
当我尝试在static const int X = 1; 中使用DoSomething 和‘const int A::X’ is private 中的X 时,我得到within this context。
我该如何解决这个问题?
【问题讨论】:
-
请发布一些语法上有效的 C++ 代码。
-
也许你应该把它改成
public: static const int X = 1; -
A.hpp是不是很重要还是只是输入错误?
标签: c++ class static-members