C++ 这个输出是如何从C++;比较器和how bool运算符>;()康斯特在工作
有人能解释一下这个程序的输出吗?我无法理解布尔运算符>()常量是如何生成此输出的C++ 这个输出是如何从C++;比较器和how bool运算符>;()康斯特在工作,c++,stl,comparator,C++,Stl,Comparator,有人能解释一下这个程序的输出吗?我无法理解布尔运算符>()常量是如何生成此输出的 #include <bits/stdc++.h> using namespace std; class Person { public: float age; string name; bool operator>(const Person &rhs) const { cout << age << " &q
#include <bits/stdc++.h>
using namespace std;
class Person
{
public:
float age;
string name;
bool operator>(const Person &rhs) const
{
cout << age << " " << rhs.age << endl;
return age > rhs.age;
}
};
int main()
{
multiset<Person, greater<>> multiset = {
{25, "Rupesh"},
{30, "Hitesh"},
{20, "Ram"}};
return 0;
}
std::multiset
还必须测试是否相等。这可以从对操作符>
的两个调用中综合出来。例如:!(a>b | | b>a)
对比较运算符的精确调用取决于multiset
的实现。
30 25
30 25
30 25
20 25
20 25