关于C++语言运算符重载的问题!编译报错说存在运算符二义性,请问如何修改?
#include<iostream>#include<string>
using namespace std;
class String
{
public:
String();
String(char*p);
void display();
friend bool operator>(String &a,String &b);
friend bool operator==(String &a,String &b);
friend bool operator<(String &a,String &b);
public:
char *p;
};
bool operator>(String &a,String &b)
{
if(strcmp(a.p,b.p)>0)
return true;
else
return false;
}
bool operator<(String &a,String &b)
{
if(strcmp(a.p,b.p)<0)
return true;
else
return false;
}
bool operator==(String &a,String &b)
{
if(strcmp(a.p,b.p)==0)
return true;
else
return false;
}
void String::display()
{
cout<<p<<endl;
}
String::String()
{
p=NULL;
}
String::String(char*x)
{
p=x;
}
int main()
{
String a=String("Hello");
String b=String("Kimi");
cout<<(a>b)<<endl;
cout<<(a==b)<<endl;
cout<<(a<b)<<endl;
}