Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

templated codes works fine under G++ but error under VC++

Here are the codes, which work fine under g++, but give error under 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!

The error messages are:

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

error C2065: 'status_': undeclared identifier

error C2131: expression did not evaluate to a constant

like image 850
blackball Avatar asked Oct 31 '22 08:10

blackball


1 Answers

Define status and it will work. See below. As for standard, I do not know which compiler is correct.

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;
}
like image 103
zdf Avatar answered Nov 15 '22 07:11

zdf