各位大侠,小弟请教个问题
下面程序不知道错在何处,请高手指教#include "stdafx.h"
#include <iostream>
#include <cstring>
using namespace std;
class String
{
public:
String(){p=NULL;}
String(char *str);
void display();
bool operator>(String &String2);
bool operator<(String &String2);
bool operator==(String &String2);
void compare(String &,String &);
private:
char *p;
};
String::String(char *str)
{
p=str;
}
bool String::operator>(String &String2)
{
if(strcmp(this->p,String2.p)>0)
return true;
else return false;
}
bool String::operator<(String &String2)
{
if(strcmp(this->p,String2.p)<0)
return true;
else return false;
}
bool String::operator==(String &string2)
{
if(strcmp(this->p,string2.p)==0)
return true;
else return false;
}
void String::display()
{
cout<<p;
}
void String::compare(String &string1,String &string2)
{
if(operator>(string2)==1)
{string1.display();cout<<">";string2.display();}
else
if(operator<(string2)==1)
{string1.display();cout<<"<";string2.display();}
else
if(operator==(string2)==1)
{string1.display();cout<<"=";string2.display();}
cout<<endl;
}
void main()
{
String string1("hello"),string2("book"),string3("computer"),string4("hello");
compare(string1,string2);
compare(string2,string3);
compare(string3,string4);
}