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 on 2008-12-02 19:39 黄琴 阅读(1550) 评论(6)  编辑 收藏 引用

FeedBack:
# re: C++重载符问题
2008-12-02 22:35 | zoyo
s1==s2 is 0
s1<s2 is 1
s1>s2 is 0  回复  更多评论
  
# re: C++重载符问题
2008-12-02 22:52 | 黄琴
呵呵。。。。对啊,经改正后就是你的这个结果  回复  更多评论
  
# re: C++重载符问题
2008-12-03 11:44 | 11
111  回复  更多评论
  
# re: C++重载符问题
2008-12-05 08:41 | zhusir
楼主的问题是什么啊?  回复  更多评论
  
# re: C++重载符问题
2008-12-05 13:19 | C--
楼主想表达啥  回复  更多评论
  
# re: C++重载符问题[未登录]
2008-12-05 19:04 | 黄琴
谢谢大家啊,我现在没有问题了,寂静解决了  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2008年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用链接

留言簿(1)

随笔档案

文章分类

文章档案

相册

搜索

  •  

最新评论