STL模板的函数对象问题

lkjasdf9909 lkjasdf9909 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
STL模板的函数对象是greater源代码是:
[
template<class _Ty = void>
struct greater
: public binary_function<_Ty, _Ty, bool>
{ // functor for operator>
bool operator()(const _Ty& _Left, const _Ty& _Right) const
{ // apply operator> to operands
return (_Left > _Right);
}
};
/code]
如果我传递一个Person对象 然后Person对象重载 > <运算符 这样可不可以?
[code=c]
class Person
{
public:
string name;
int age;
bool operator<(const Person& obj)
{
return (this->age < obj.age);
}
bool operator>(const Person& obj)
{
return (this->age > obj.age);
}
};


因为我在写代码的时候
greater<string>这样写是不会报错的
string 就有< >的运算符重载函数
所以我想Person能不能这样写
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
lkjasdf9909
C++ 语言 65,214 成员 250,514 内容