posts - 1,  comments - 6,  trackbacks - 0

最近做了老师布置的一个运算符重载题,发现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 @ 2008-12-02 19:39 黄琴 阅读(1550) | 评论 (6)编辑 收藏
仅列出标题  
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(1)

随笔档案

文章分类

文章档案

相册

搜索

  •  

最新评论