(C++)各位大侠帮忙看看这个双目运算符的重载有什么问题
hmjia 2009-04-14 11:37:14 #include <iostream>
#include <string>
using namespace std;
class String
{public:
String( ){p=NULL;}
String(char *str);
friend bool operator>(String &string1,String &string2);
void display();
private:
char *p;
};
String::String(char *str)
{p=str;}
void String::display()
{
cout<<p;
}
bool operator>(String &string1,String &string2)
{
if(strcmp(string1.p,string2.p)>0)
return true;
else
return false;
}
void main()
{
String str1("Hello "),str2("world!");
str1.display();
str2.display();
cout<<(str1>str2)<<endl;
}
用VC++6.0编译报错:error C2248: 'p' : cannot access private member declared in class 'String' ,see declaration of 'p'。
error C2593: 'operator >' is ambiguous。