#include
using namespace std;
The class String
{
Public:
String () {p=NULL; }
String STR (char *);
Friend Boolean operator & gt; (String & amp; String1, String & amp; String2);
Friend Boolean operator & lt; (String & amp; String1, String & amp; String2);
Friend Boolean operator==(String & amp; String1, String & amp; String2);
Void the display ();
Private:
Char * p;
};
String: : String STR (char *)
{
P=STR.
}
Void String: : display ()
{
cout <& lt; p;
}
Boolean operator & gt; (String & amp; String1, String & amp; String2)
{
If (STRCMP (string1. P, string2. P) & gt; 0)
return true;
The else
return false;
}
Boolean operator & lt; (String & amp; String1, String & amp; String2)
{
If (STRCMP (string1. P, string2. P) & lt; 0)
return true;
The else
return false;
}
Boolean operator==(String & amp; String1, String & amp; String2)
{
If (STRCMP (string1. P, string2. P)==1)
return true;
The else
return false;
}
Void the compare (String & amp; String1, String & amp; String2)
{
If (operator & gt; (string1, string2)==1)
{
String1. The display (); cout <& lt; "& gt;"; String2. The display ();
}
The else
If (operator & lt; (string1, string2)==1)
{
String1. The display (); cout <& lt; "& lt;"; String2. The display ();
}
The else
If (operator==(string1, string2)==1)
{
String1. The display (); cout <& lt; "="; String2. The display ();
}
cout <& lt; endl;
}
Int main ()
{
String string1 (" Hello "), string2 (" Book "), string3 (" Computer "), string4 (" Hello ");
Compare (string1, string2);
Compare (string2, string3);
Compare (string1, string4);
return 0;
}
This is a simple c + + programs, I want to ask
Friend Boolean operator & gt; (String & amp; String1, String & amp; String2);
Friend Boolean operator & lt; (String & amp; String1, String & amp; String2);
Friend Boolean operator==(String & amp; String1, String & amp; String2);
Void the display ();
The String inside & amp; String1, String & amp; String2
What do you mean? Why to be like this?
CodePudding user response:
Reference, is a bit like the pointer in C; Incoming references, you will not copy copy, high efficiency, and is a real comparing the two Numbers, but without this reference, this is a copy of the two in comparison...CodePudding user response:
References - http://my.oschina.net/alphajay/blog/5251