编译提示:error C2593: 'operator >' is ambiguous
#include<iostream>#include<string>usingnamespacestd;classString{public:String(){p=NUL...
#include<iostream>
#include<string>
using namespace std;
class String
{
public:
String (){
p=NULL;
}
String(char *p);
void display();
friend bool operator >(String&string1,String&string2);
//private:
char *p;
};
int main()
{
void compare(String&string1,String&string2);
String string1("hello"),string2("book");
compare(string1,string2);
// cout<<(string1>string2)<<endl;
return 0;
}
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;
}
void compare(String&string1,String&string2)
{
if((string1>string2)==1)
{
string1.display();
cout<<">"<<endl;
string2.display();
}
else
cout<<"false"<<endl;
}
提示错误: 展开
#include<string>
using namespace std;
class String
{
public:
String (){
p=NULL;
}
String(char *p);
void display();
friend bool operator >(String&string1,String&string2);
//private:
char *p;
};
int main()
{
void compare(String&string1,String&string2);
String string1("hello"),string2("book");
compare(string1,string2);
// cout<<(string1>string2)<<endl;
return 0;
}
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;
}
void compare(String&string1,String&string2)
{
if((string1>string2)==1)
{
string1.display();
cout<<">"<<endl;
string2.display();
}
else
cout<<"false"<<endl;
}
提示错误: 展开
1个回答
2010-10-08
展开全部
说操作符 > 具有双义性,不能用
比较俩string用 strcmp啊!
比较俩string用 strcmp啊!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询