简体   繁体   English

如何在C ++模板代码中修复'预期的'primary-expression'错误?

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

Here's yet another VC9 vs. GCC 4.2 compile error problem. 这是另一个VC9与GCC 4.2编译错误问题。 The following code compiles fine with VC9 (Microsoft Visual C++ 2008 SP1) but not with GCC 4.2 on Mac: 以下代码使用VC9(Microsoft Visual C ++ 2008 SP1)编译,但不适用于Mac上的GCC 4.2:

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 . 模板中的从属名称不是 类型,除非您指定它们是通过typename并假定不是 模板,除非通过template指定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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