Template codes work fine under g ++, but a bug in VC ++

Here are the codes that work fine under g++ but give an error in 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; } 

Why? Thanks!

Error messages:

error C2039: 'status_': not a member of 'Foo'

error C2065: 'status_': undeclared identifier

error C2131: expression was not evaluated by constant

+5
source share
1 answer

Define status and it will work. See below. As for the standard, I don't know which compiler is right.

 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; } 
+2
source

Source: https://habr.com/ru/post/1244042/


All Articles