相关疑难解决方法(0)

模板外的typename

这在VS2010sp1中没有编译(虽然它使用gcc 4.6进行编译):

template<class T>
struct Upcast;

template<>
struct Upcast<signed char>
{
    typedef signed short type;
};

template<>
struct Upcast<char>
{
    typedef typename std::conditional<std::is_signed<char>::value,short, unsigned short>::type type;
};

int main()
{
    Upcast<char>::type a;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

来自VS的错误:

Error   1   error C2899: typename cannot be used outside a template declaration
Run Code Online (Sandbox Code Playgroud)

哪支队伍是对的?VS还是gcc?

c++ templates

20
推荐指数
2
解决办法
9577
查看次数

标签 统计

c++ ×1

templates ×1