简体   繁体   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>          ]

here is the code that generates the error... 这是生成错误的代码...

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

So we have a list of functors that return void and take an argument of type shared_ptr. 因此,我们有一个函子列表,这些函子返回void并采用shared_ptr类型的参数。 Does anyone know why the MSVC compiler is having trouble? 有谁知道为什么MSVC编译器遇到问题?

while compiling class template member function 'void std::list<_Ty>::remove(const _Ty &)' with [ _Ty=ServerLoginResponseCallback ] 使用[_Ty = ServerLoginResponseCallback]编译类模板成员函数'void std :: list <_Ty> :: remove(const _Ty&)'

You are instantiating std::list<std::function<void (ServerLoginResponsePtr)>> , and trying to call erase on it, and that depends on calling operator== on two std::function objects, but std::function s are not comparable (only to nullptr ): 您正在实例化std::list<std::function<void (ServerLoginResponsePtr)>> ,并尝试对其调用erase ,这取决于在两个std::function对象上调用operator== ,但std::function s不具有可比性(仅与nullptr ):

§20.8.14.2 [func.wrap.func] (from the final draft n3092): §20.8.14.2[func.wrap.func](摘自n3092最终草案):

Member functions: 成员功能:

// 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;

These are free functions: 这些是免费功能:

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...)>&);

It seems you have problems with instantiation. 看来您在实例化方面遇到了问题。 I've just tried to reproduce your bug but my MSVC compiled this code successfully. 我刚刚尝试重现您的错误,但是我的MSVC成功地编译了此代码。

Please, show us more code )) For example, show us how you use this list after creation. 请向我们显示更多代码))例如,向我们显示创建后如何使用此列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM