簡體   English   中英

MSVC 2010模板編譯器問題

[英]MSVC 2010 templates compiler problem

1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\list(1194): error C2451: conditional expression of type 'void' is illegal
1>          Expressions of type void cannot be converted to other types
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\list(1188) : while compiling class template member function 'void std::list<_Ty>::remove(const _Ty &)'
1>          with
1>          [
1>              _Ty=ServerLoginResponseCallback
1>          ]
1>          c:\users\shawn\edu\csclient\ConfigurationServerClient.h(56) : see reference to class template instantiation 'std::list<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=ServerLoginResponseCallback
1>          ]

這是生成錯誤的代碼...

typedef std::shared_ptr<protocols::ServerLoginResponse> ServerLoginResponsePtr;
typedef std::function<void (ServerLoginResponsePtr)> ServerLoginResponseCallback;
typedef std::list<ServerLoginResponseCallback> ServerLoginResponseCallbackList;

因此,我們有一個函子列表,這些函子返回void並采用shared_ptr類型的參數。 有誰知道為什么MSVC編譯器遇到問題?

使用[_Ty = ServerLoginResponseCallback]編譯類模板成員函數'void std :: list <_Ty> :: remove(const _Ty&)'

您正在實例化std::list<std::function<void (ServerLoginResponsePtr)>> ,並嘗試對其調用erase ,這取決於在兩個std::function對象上調用operator== ,但std::function s不具有可比性(僅與nullptr ):

§20.8.14.2[func.wrap.func](摘自n3092最終草案):

成員功能:

// deleted overloads close possible hole in the type system
template<class R2, class... ArgTypes2> 
bool operator==(const function<R2(ArgTypes2...)>&) = delete;

template<class R2, class... ArgTypes2> 
bool operator!=(const function<R2(ArgTypes2...)>&) = delete;

這些是免費功能:

template<class R, class... ArgTypes> 
bool operator==(const function<R(ArgTypes...)>&, nullptr_t);

template<class R, class... ArgTypes>
bool operator==(nullptr_t, const function<R(ArgTypes...)>&);

看來您在實例化方面遇到了問題。 我剛剛嘗試重現您的錯誤,但是我的MSVC成功地編譯了此代碼。

請向我們顯示更多代碼))例如,向我們顯示創建后如何使用此列表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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