pmatos wrote:
Hi all,
I'm overloading operator<< for a lot of classes. The question is about
style. I define in each class header the prototype of the overloading
as a friend.
Do you actually need that?
Now, where should I define the overloading of operator<<.
In the .cc of the respective class or in a file where I am overloading
operator<< for all classes?
I'd choose the former for three reasons.
1. It simplifies dependancies. If you put all the operators in one
implementation file, that file needs to #include the headers of all the
classes that you have operator<< for.
2. If you add or change a class and the operator<< needs to be adapted, you
have to touch two files instead of one.
3. IHMO, it's a good idea if things that are declared in a header are
defined in the corresponding implementation file and not somewhere else.