There is nothing wrong with the code, and it compiles fine with GCC and Clang. The problem is with Visual C ++.
Initializer lists are one of the features that will be available in Visual Studio 2012 Update 2 . This means that you cannot use this feature in Visual Studio 2012. There is a series of Community Tech Previews (CTP) , but they come with some minor issues, including the lack of IntelliSense support and very clear disclaimers saying that they are not Designed for use in production code.
So, in short: your code is correct, but it will not compile in VS2012 until Microsoft releases the Visual Studio 2012 2 update. There is no information when this will happen, but Visual Studio 2012 was first released in August 2012 and the last The update (Update 1) was released in November 2012. Since then there has been little news, but it has been "soon" since the end of last year.
Update Now Update 2 has been released. However, it does not include any of the promised C ++ enhancements from CTP Update 2. This is ridiculous given that they should be previews of what should appear in Update 2. Apparently, the Visual C ++ team "is currently finalizing release plans for of these functions, "and" will tell you more soon. " (from comments Update 2 release .
source share