C++ MSVC 2010模板编译器问题 1>C:\Program Files(x86)\Microsoft Visual Studio 10.0\VC\include\list(1194):错误C2451:类型为“void”的条件表达式非法 1> void类型的表达式无法转换为其他类型 1> C:\ProgramFiles(x86)\Microsoft Visual Studio 10.0\VC\include\list(1188):编译类模板成员函数“void std::list::remove(const _Ty&)”时 1> 与 1> [ 1> _Ty=ServerLoginResponseCallback 1> ] 1> c:\users\shawn\edu\csclient\ConfigurationServerClient.h(56):请参阅正在编译的类模板实例化“std::list”的参考 1> 与 1> [ 1> _Ty=ServerLoginResponseCallback 1> ]

C++ MSVC 2010模板编译器问题 1>C:\Program Files(x86)\Microsoft Visual Studio 10.0\VC\include\list(1194):错误C2451:类型为“void”的条件表达式非法 1> void类型的表达式无法转换为其他类型 1> C:\ProgramFiles(x86)\Microsoft Visual Studio 10.0\VC\include\list(1188):编译类模板成员函数“void std::list::remove(const _Ty&)”时 1> 与 1> [ 1> _Ty=ServerLoginResponseCallback 1> ] 1> c:\users\shawn\edu\csclient\ConfigurationServerClient.h(56):请参阅正在编译的类模板实例化“std::list”的参考 1> 与 1> [ 1> _Ty=ServerLoginResponseCallback 1> ],c++,visual-c++,templates,C++,Visual C++,Templates,下面是生成错误的代码 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:\Prog

下面是生成错误的代码

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标准::共享服务器登录应答器;
typedef std::函数ServerLoginResponseCallback;
typedef std::list ServerLoginResponseCallbackList;

我们有一个返回void并接受shared\u ptr类型参数的函子列表。有人知道MSVC编译器出现问题的原因吗?

您似乎在实例化方面有问题。我刚刚试图重现你的错误,但是我的MSVC成功地编译了这段代码


请向我们展示更多代码)例如,向我们展示创建后如何使用此列表。

似乎您在实例化方面存在问题。我刚刚试图重现你的错误,但是我的MSVC成功地编译了这段代码

请向我们展示更多代码(例如,向我们展示创建后如何使用此列表

编译类模板成员函数“void std::list::remove(const _Ty&)”时 使用[\u Ty=ServerLoginResponseCallback]

您正在实例化
std::list
,并尝试对其调用
erase
,这取决于对两个
std::function
对象调用
operator=
,但
std::function
不可比较(仅对
nullptr
):

§20.8.14.2[功能总结功能](摘自最终草案n3092):

成员职能:

typedef std::shared_ptr<protocols::ServerLoginResponse> ServerLoginResponsePtr;
typedef std::function<void (ServerLoginResponsePtr)> ServerLoginResponseCallback;
typedef std::list<ServerLoginResponseCallback> ServerLoginResponseCallbackList;
// 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;
//删除的重载关闭了类型系统中可能存在的漏洞
模板
布尔运算符==(常量函数&)=删除;
模板
接线员=(常量函数&)=删除;
这些是自由函数:

typedef std::shared_ptr<protocols::ServerLoginResponse> ServerLoginResponsePtr;
typedef std::function<void (ServerLoginResponsePtr)> ServerLoginResponseCallback;
typedef std::list<ServerLoginResponseCallback> ServerLoginResponseCallbackList;
// 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;
模板
布尔运算符==(常量函数&,null ptr_t);
模板
布尔运算符==(nullptr_t,常量函数&);
编译类模板成员函数“void std::list::remove(const _Ty&)”时 使用[\u Ty=ServerLoginResponseCallback]

您正在实例化
std::list
,并尝试对其调用
erase
,这取决于对两个
std::function
对象调用
operator=
,但
std::function
不可比较(仅对
nullptr
):

§20.8.14.2[功能总结功能](摘自最终草案n3092):

成员职能:

typedef std::shared_ptr<protocols::ServerLoginResponse> ServerLoginResponsePtr;
typedef std::function<void (ServerLoginResponsePtr)> ServerLoginResponseCallback;
typedef std::list<ServerLoginResponseCallback> ServerLoginResponseCallbackList;
// 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;
//删除的重载关闭了类型系统中可能存在的漏洞
模板
布尔运算符==(常量函数&)=删除;
模板
接线员=(常量函数&)=删除;
这些是自由函数:

typedef std::shared_ptr<protocols::ServerLoginResponse> ServerLoginResponsePtr;
typedef std::function<void (ServerLoginResponsePtr)> ServerLoginResponseCallback;
typedef std::list<ServerLoginResponseCallback> ServerLoginResponseCallbackList;
// 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;
模板
布尔运算符==(常量函数&,null ptr_t);
模板
布尔运算符==(nullptr_t,常量函数&);

错误消息不是来自三个TypeDef,是吗?它们不实例化std::list错误消息不是来自三个typedef,是吗?它们不会实例化问题所在的std::list。我有一个remove函数,无法比较函子。我还需要研究更多的管理函数集合的方法,这就是问题所在。我有一个remove函数,无法比较函子。我还需要进一步研究管理函数集合的方法。谢谢David。关于管理std::function对象集合的任何提示?出于您的特殊目的,我建议您使用
boost::signal
(或
boost::signal2
)。他们的解决方案IIRC为每个函数注册返回一个令牌。该令牌稍后可用于断开客户端连接。谢谢David。关于管理std::function对象集合的任何提示?出于您的特殊目的,我建议您使用
boost::signal
(或
boost::signal2
)。他们的解决方案IIRC为每个函数注册返回一个令牌。该令牌稍后可用于断开客户端的连接。