[英]Unified initialization syntax in C++11
The question about “unified initialization syntax” in C++11. C ++ 11中有关“统一初始化语法”的问题。
Is it legal to initialize the struct with the next syntax in C++11 (look at lines #128-137)? 使用C ++ 11中的下一种语法初始化结构是否合法(请参见第128-137行)? Or POD is still actual?
还是POD仍然是实际的?
http://pastebin.com/GMZ5QDmR http://pastebin.com/GMZ5QDmR
The problem with MSVC 2013 compiler. MSVC 2013编译器的问题。 This example compiles successfully, but crashes with bad function call exception.
此示例成功编译,但由于错误的函数调用异常而崩溃。 That told to me the std::function object not initialized properly.
这告诉我std :: function对象未正确初始化。
By the way, the ICC 13.0 can not compile the code in the example. 顺便说一下,ICC 13.0无法在示例中编译代码。
example.cpp(130): error #2084: designator may not specify a non-POD (Plain Old Data) subobject
example.cpp(130):错误#2084:指定者可能未指定非POD(普通旧数据)子对象
Is it defect in compilers? 它在编译器中有缺陷吗? Or with compilers all is ok, and such approach is not compliant with C++11?
还是使用编译器都可以,并且这种方法与C ++ 11不兼容?
Here is short example: 这是一个简短的示例:
#include <functional>
#include <memory>
struct dispatcher_t {};
struct binder_t {};
struct factories_t
{
std::function< std::unique_ptr< dispatcher_t > () > m_disp_factory;
std::function< std::unique_ptr< binder_t > () > m_bind_factory;
};
std::unique_ptr< dispatcher_t >
create_dispatcher()
{
return std::unique_ptr< dispatcher_t >( new dispatcher_t() );
}
std::unique_ptr< binder_t >
create_binder()
{
return std::unique_ptr< binder_t >( new binder_t() );
}
void main()
{
factories_t f{
[]() { return create_dispatcher(); },
[]() { return create_binder(); }
};
}
First: void main
is illegal in C++. 第一:
void main
在C ++中是非法的。 Use int main
. 使用
int main
。
Microsoft Visual Studio 2013 isn't the star of the C++11 class. Microsoft Visual Studio 2013并不是C ++ 11类的明星。 Neither is Intel's compiler version 13, because, well, they have version 14. That being said, you can try the MSVC++ 2013 November CTP , which is a tiny bit better on the language support.
英特尔的编译器版本13都不是,因为它们的版本是14。也就是说,您可以尝试MSVC ++ 2013年11月CTP ,它在语言支持上要好一点。
If you want to see if your code is valid, use the latest version of GCC or Clang, both available on the Greatest Online Compiler Platform in Existence . 如果要查看代码是否有效,请使用最新版的GCC或Clang,这两种版本都可以在存在的最大在线编译器平台上找到 。
The C++ language features are reported on the vendor's websites: 在供应商的网站上报告了C ++语言功能:
Any other C++ compiler isn't worth mentioning wrt C++11. 其他任何C ++编译器都不值得提及wrt C ++ 11。
Note that the Standard library features may not be mentioned on these pages. 请注意,这些页面上可能未提及标准库功能。
The feature you are looking usually falls under "(general) initializer lists". 您要查找的功能通常位于“(常规)初始化列表”下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.