【发布时间】:2013-07-14 05:39:59
【问题描述】:
所有,
这是this线程的延续。
我尝试的是编写以下代码:
struct Remover : public std::binary_function<CPlayer,void,bool>
{
public:
bool operator()(const CPlayer &player) const
{
return player.IsNewPlayer();
}
};
这样称呼它:
players_pool->erase( std::remove_if( players_pool->begin(), players_pool->end(), std::bind2nd( Remover() ) ) );
但它给了我一个错误:
std::bind2nd():需要 2 个参数 - 提供 1 个。
如何正确调用这个函子?
谢谢。
【问题讨论】:
-
您了解错误信息吗?
expects 2 arguments - 1 provided.- 另外,您阅读过std::bind2nd()的文档吗? -
您既不需要
bind2nd,也不需要Remover。看std::mem_fun。 -
@n.m.请注意,
std::mem_fun已弃用。但std::mem_fn可能是另一种选择。 -
@juanchopanza 是的,如果您使用的是 C++11,那就对了。