下面是代码,在g++
下运行良好,但在VC++ 2014
下出错:
template <class A>
struct Expression
{
public:
static const int status = A::status_;
};
struct Foo : public Expression<Foo>
{
static const int status_ = 0;
};
int main(void) {
return 0;
}
为什么?谢谢!
错误信息是:
error C2039: 'status_': is not a member of 'Foo'
error C2065: 'status_': undeclared identifier
error C2131: expression did not evaluate to a constant
最佳答案
定义 status
它将起作用。见下文。至于标准,我不知道哪个编译器是正确的。
template <class A>
struct Expression
{
public:
static const int status;
};
struct Foo : public Expression<Foo>
{
static const int status_ = 0;
};
template< typename A >
const int Expression<A>::status = A::status_;
int main( void ) {
return 0;
}
关于c++ - 模板代码在 G++ 下工作正常,但在 VC++ 下出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35682420/