运算符重载总是出现问题。
刚刚学会的重载,结果编译出来老是出现'operator >' is ambiguous,有什么错误吗。。。#include<iostream>
#include<string>
using namespace std;
class String
{
public:
String(){p=NULL;}
String(char *str);
void display();
friend bool operator >(String &string1,String &string2);
char *p;
};
bool operator >(String &string1,String &string2)
{
if(strcmp(string1.p,string2.p)>0)
return true;
else return false;
}
String::String(char *str)
{p=str;}
void String::display()
{cout<<p;}
int main()
{
String string1("Hello"),string2("Book");
cout<<(string1 >string2)<<endl;
}