最近做了老师布置的一个运算符重载题,发现VC6.0实在的。。。。。我不敢恭维啊
#include<iostream>
#include<string>
//using namespace std;
//我本来用的是上面这句的,而不是用下面三句using 的,结果报错。
//error C2593:'operator ==' is ambiguous
//error C2593: 'operator <' is ambiguous
//error C2593: 'operator >' is ambiguous
using std::string;
using std::cout;
using std::endl;
class String{
public :
String(){}
String(string p){ str=p; }
//friend String operator =(String s1,String s2);
friend bool operator ==(const String& s1,const String& s2);
friend bool operator >(const String& s1,const String& s2);
friend bool operator <(const String& s1,const String& s2);
//void display();
string str;
};
bool operator ==(const String& s1,const String& s2){
return s1.str==s2.str;
}
bool operator >(const String& s1,const String& s2){
return s1.str>s2.str;
}
bool operator <(const String& s1,const String& s2){
return s1.str<s2.str;
}
int main()
{
String s1("Hello");
String s2("World");
bool b; //若b 为真则返回1,若为假则返回0
b=(s1==s2);
cout<<"s1==s2 is "<<b<<endl;
b=(s1<s2);
cout<<"s1<s2 is "<<b<<endl;
b=(s1>s2);
cout<<"s1>s2 is "<<b<<endl;
return 0;
}
posted on 2008-12-02 19:39
黄琴 阅读(1569)
评论(6) 编辑 收藏 引用