views:

69

answers:

2
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. Does anyone know why the MSVC compiler is having trouble?

+1  A: 

It seems you have problems with instantiation. I've just tried to reproduce your bug but my MSVC compiled this code successfully.

Please, show us more code )) For example, show us how you use this list after creation.

GooRoo
That is the issue. I have a remove function and there is no way to compare Functors. I'll have to research a bit more on ways to manage collections of Functors.
shaz
+3  A: 

while compiling class template member function 'void std::list<_Ty>::remove(const _Ty &)' with [ _Ty=ServerLoginResponseCallback ]

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::functions are not comparable (only to nullptr):

§20.8.14.2 [func.wrap.func] (from the final draft 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...)>&);
David Rodríguez - dribeas
Thanks David. Any tips on managing a collection of std::function objects?
shaz
For your particular purpose, I would just recommend using `boost::signal` (or `boost::signal2`). Their solution, IIRC, is returning a token to each function registration. That token can later be used to disconnect the client.
David Rodríguez - dribeas