簡體   English   中英

C ++ 11中的統一初始化語法

[英]Unified initialization syntax in C++11

C ++ 11中有關“統一初始化語法”的問題。

使用C ++ 11中的下一種語法初始化結構是否合法(請參見第128-137行)? 還是POD仍然是實際的?

http://pastebin.com/GMZ5QDmR

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM