首页 文章

VS2015拒绝未命名类型的类内初始化

提问于
浏览
0

以下代码无法在VS2015中编译 .

struct Foo
{
    Foo(int value) { }
};

struct Moo
{
    struct
    {
        Foo foo = 0;
    } fooHolder;
};


int main()
{
    Moo moo;
}

显示以下错误 .

1>c:\xxx\main.cpp(81): error C2512: 'Foo' : no appropriate default constructor available
1>          This diagnostic occurred in the compiler generated function 'Moo::<unnamed-type-fooHolder>::(void) restrict(cpu, amp)'

如果为未命名的struct指定了名称,则代码将进行编译 .

struct NamedHolder
{
    Foo foo = 0;
} fooHolder;

用clang和gcc编译的代码 . http://coliru.stacked-crooked.com/a/3b4ab035a967eed9

它拒绝有效的代码吗?

1 回答

  • 1

    这段代码完全没问题,它可以编译VS2015 Update 1 RC(刚刚验证过) . 也许你错过了一些东西 . 我测试的系统:

    Microsoft Visual Studio社区2015版本14.0.24627.00更新1 RC Microsoft .NET Framework版本4.6.01040已安装版本:Community Visual C 2015 RC 00322-20000-00000-AA392 Microsoft Visual C 2015 RC ...

相关问题