2015-11-21 33 views
0

以下代碼無法在VS2015中編譯。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 NamedHolder 
{ 
    Foo foo = 0; 
} fooHolder; 

在clang和gcc編譯的代碼。 http://coliru.stacked-crooked.com/a/3b4ab035a967eed9

它拒絕有效的代碼嗎?

+0

@ 101010我不知道。我的意思是符合標準。 – typ1232

+0

我有Visual C++ 2015 00322-20000-00000-AA794,工作正常。 – 101010

+0

@ 101010您是否安裝了Update 1 RC?我的版本是00322-90053-68603-AA603。 – typ1232

回答

1

此代碼非常好,它編譯VS2015更新1 RC(剛剛驗證)。也許你錯過了一些東西。該系統上,我測試:

微軟的Visual Studio 2015年社區

版本14.0.24627.00更新1 RC

的Microsoft .NET Framework

版本4.6.01040

安裝版本:社區

Visual C++ 2015 RC 00322-20000-0000 0-AA392 微軟的Visual C++ 2015年RC

...

+0

我將它配置爲使用VS2013編譯器。 – typ1232