Pre {Line-Height: 1; color: # 1e1e1e; Background-color: # d2d2d2; font-size: 16px ;}. sysfunc {color: #627cf6; font-style: italic; font-weight: bold ;}. selffuc {color: #800080 ;}. bool {color: # d2576f ;}. condition {color: #000080; font-weight: bold ;}. key {color: #000080 ;}. vaR {color: #800000; font-style: italic ;}. digit {color: # ff00ff; font-weight: bold ;}. includepre {color: # 1e1e1e ;}. operator? {Color: #008000; font-weight: bold ;}
Operator overload
? # Include? <Iostream> # include? <String> using? Namespace? STD ;? // Define the fruit category? Class? Fruit {?? String? Name ;?? String? Color; public :????????? Friend? Istream &? Operator> (istream &, Fruit &);???????????????????? //? Input stream ????????? Friend? Ostream &? Operator <(ostream &? Out, const? Fruit &? Fruit );??????? //? Output stream ????????? Void? Print ()????????? {??????????????????? Cout <color <"? "<Name <Endl ;?????????}?????????? Fruit (const? String? NST = "apple", const? String? CST = "green"): Name (NST), color (CST )????????? {?????????}??????????~ Fruit ()????????? {?????????}};?? // Overload operator ostream &? Operator <(ostream &? Out ,? Const? Fruit? & S ){????????? Out <S. Color <"? "<S. Name <Endl ;????????? Return? Out ;?}? Istream &? Operator> (istream &? In, fruit? & S ){????????? In> S. Color> S. Name ;????????? If? (! In )????????? {??????????????????? Cerr <"wrong? Input! "<Endl ;?????????}????????? Return? In ;}???
Main Program:
?????????Fruit?apple;?????????cin>>apple;?????????cout<<apple;?
Used in this article? Calligraphy and painting novel software? Released, the content has nothing to do with the software, and the painting and calligraphy novel software? More comfortable reading, more comfortable writing, and easier Publishing.
Operator overload. xml