简体   繁体   中英

How to fix 'expected primary-expression before' error in C++ template code?

Here's yet another VC9 vs. GCC 4.2 compile error problem. The following code compiles fine with VC9 (Microsoft Visual C++ 2008 SP1) but not with GCC 4.2 on Mac:

struct C
{
    template< typename T >
    static bool big() { return sizeof( T ) > 8; }
};

template< typename X >
struct UseBig
{
    static bool test()
    {
        return X::big< char >(); // ERROR: expected primary-expression
    }                            // before 'char'
};

int main()
{
    C::big< char >();
    UseBig< C >::test();
    return 0;
}

Any ideas how I can fix this?

That should be

return X::template big< char >();

Dependent names from templates are taken to not be types unless you specify that they are via typename and assumed to not be templates unless specified via template .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM