Bloomberg LP Interview Question
Software Engineer / DevelopersTeam: Price history
Country: United States
Interview Type: In-Person
Using it in the class will make many thing simpler.
The most significant thing is you can access to local protected and private variables and functions.
class Mytest {
friend ostream& operator << (ostream& o, const Mytest& c) { return o << "test " << c.tel; }
int tel;
};
int main() {
Mytest t;
cout << t <<endl;
}
Using it in the class will make many thing simpler.
The most significant thing is you can access to local protected and private variables and functions.
class Mytest {
friend ostream& operator << (ostream& o, const Mytest& c) { return o << "test " << c.tel; }
int tel;
};
int main() {
Mytest t;
cout << t <<endl;
}
<< operator is usually implemented as a non-member function,and it should be a friend function.If be a member function,you must use it as'object << cout',it is opposite to general use of <<.
- zhangsw126 August 23, 2014