C ++编译问题-C2332:

问题描述 投票:0回答:1

VS 2005->编译没有任何错误。

VS 2010->编译有任何错误。

例如代码段

template< bool f > struct static_assert;
template<>         struct static_assert<true> { static_assert() {} };

编译器错误:

错误C2332:'结构':缺少标签名称

例如代码段

template< typename T >
class abcd
{
    struct xyz
    {
        xyz();
        char    c;
        T       tt;
    };
public:
    enum { value = sizeof(xyz)-sizeof(T) < sizeof(T) ? sizeof(xyz)-sizeof(T) : sizeof(T) };
};

编译器错误:

错误C2332:“类”:缺少标签名称

任何建议。

c++ visual-studio-2010 templates visual-studio-2005
1个回答
0
投票

[在您的第一个代码段中,问题是static_assert在C ++ 11标准(VS-2010似乎正在使用此代码)中变成了reserved keyword,而在以前的版本中是“允许”标识符语言(例如VS-2005编译器使用的语言)。要解决此问题,请更改结构的名称,即使这仅意味着更改一个或两个字母的大小写也是如此:

template< bool f > struct Static_Assert;
template<>         struct Static_Assert<true> { Static_Assert() { } };
© www.soinside.com 2019 - 2024. All rights reserved.