STL 容器的重载运算符 ==
我正在尝试从 list
l.remove(class_type);
我尝试编写这样的内容作为成员函数,
bool operator == (const class_type &a) const //not sure about the arguments
{
//return bool value
}
您如何编写一个重载函数来从 boost::any
的 std::list 中删除类的对象?
I'm trying to remove a class object from list<boost::any> l
l.remove(class_type);
I tried writing something like this as a member function
bool operator == (const class_type &a) const //not sure about the arguments
{
//return bool value
}
How would you write an overload function to remove an object of class from a std::list of boost::any
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然
operator==
的签名看起来不错,但为class_type
重载它还不够,因为boost::any
不会神奇地使用它。但是,要删除元素,您可以将谓词传递给remove_if
,例如:While your signature for
operator==
looks fine, overloading it forclass_type
isn't enough asboost::any
doesn't magically use it. For removing elements however you can pass a predicate toremove_if
, e.g.: