Home > OS >  O bosses help me to analyze the bai...
O bosses help me to analyze the bai...

Time:10-18

Compilation occurs: stringOverload. Cc: the: for error: no match for 'operator<& lt; '(operand types are' STD: : ostream {aka STD: : basic_ostream & lt; char> } 'and' void ')
cout<& lt; S1. The display () & lt; & lt; endl;


# include
# include
using namespace std;
The class String {
Public:
String (String STR)
: _str (STR)
{
cout<" Sting () "& lt; & lt; endl;
}

String operator=(const String & amp; Str2) {
Return a String (_str=str2. _str); }

Void the display () const {
cout<& lt; _str & lt; & lt; endl;
}
Private:
String _str;

};
Int main () {
String s1 (" hello ");
String s2 (" world ");
cout<" Before phrase "& lt; & lt; endl;
cout<& lt; S1. The display () & lt; & lt; endl;
//cout<& lt; S2. The display () & lt; & lt; endl;
S1=s2;
cout<" After overload "& lt; & lt; endl;
//cout<& lt; S1. The display () & lt; & lt; endl;
//cout<& lt; S2. The display () & lt; & lt; endl;
}
  • Related