有如下程序:}}}}include<iostream>using namespace std;class Pair{int m;int n;public:Pa
有如下程序:
}}}}include<iostream>
using namespace std;
class Pair{
int m;
int n;
public:
Pair(int i,int J):m(i),n(J){}
bool operator>(Pair P)const; //需在类体外给出定义
};
int main(){
Pair pl(3,4),p2(4,3),p3(4,5);
COUt<<(pl>p2)<<(p2>p1)<<(p2>p3)<<(p3>p2);
return 0;
{
运算符函数operator>功能是比较两个Pair对象的大小,当左边对象大时,返回true,否则返回false。比较规则是首先比较两对象的m成员,m大者为大;当m相等时比较n.n大者为大。程序输出0101,下列对运算符重载函数的正确定义是
A.bool Pair::operator>(Pair P)const {if(m!=P.m)return m>P.m;return n>P.n;)
B.bool Pair::operator>(Pair P) {if(m!=P.m)return m>P.m;return n>P.n;)
C.bool Pair::operator>(Pair P)const {if(m>P.m)return true;return 11>P.n;)
D.bool Pair::operator>(Pair P) {if(m>P.m)return true;return 11>P.n;}