[英]Unified initialization syntax in C++11
C ++ 11中有关“统一初始化语法”的问题。
使用C ++ 11中的下一种语法初始化结构是否合法(请参见第128-137行)? 还是POD仍然是实际的?
MSVC 2013编译器的问题。 此示例成功编译,但由于错误的函数调用异常而崩溃。 这告诉我std :: function对象未正确初始化。
顺便说一下,ICC 13.0无法在示例中编译代码。
example.cpp(130):错误#2084:指定者可能未指定非POD(普通旧数据)子对象
它在编译器中有缺陷吗? 还是使用编译器都可以,并且这种方法与C ++ 11不兼容?
这是一个简短的示例:
#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(); }
};
}
第一: void main
在C ++中是非法的。 使用int main
。
Microsoft Visual Studio 2013并不是C ++ 11类的明星。 英特尔的编译器版本13都不是,因为它们的版本是14。也就是说,您可以尝试MSVC ++ 2013年11月CTP ,它在语言支持上要好一点。
如果要查看代码是否有效,请使用最新版的GCC或Clang,这两种版本都可以在存在的最大在线编译器平台上找到 。
在供应商的网站上报告了C ++语言功能:
其他任何C ++编译器都不值得提及wrt C ++ 11。
请注意,这些页面上可能未提及标准库功能。
您要查找的功能通常位于“(常规)初始化列表”下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.