Sign in to follow this  

Operator overloads into seperate headers?

This topic is 4381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have read somewhere that one should put operator overloads into a seperate headers to keep the core implementation of classes clean What do you think about this?

Share this post


Link to post
Share on other sites
the stl implementation i use puts the operator overloads outside the class declaration but keeps them in the same header which has the advantage that you have it by hand to edit it and don t have to look for other headers

Share this post


Link to post
Share on other sites
Operator overloading means to have two parts: (1) the declaration, and (2) the definition/implementation. Both parts could be written down at the same place, as could be seen often for inlined (and more or less also template) functions. Or they could be written at different places (until up to different files).

If you say "put operator overloads into a seperate headers" so I assume both their declaration and implementation is moved in that header. However, both headers (that of the class and that of its friend operators, inline functions, and so on) have to be included in order to get knowledge of the full interface. And also the programmer has to look at both files. I don't think that the effort of handling 50% more files is it worth, since the reward is just to shrink a third of the files by approx. less than 50% (what is moved into the new files, along with some additional overhead for management).

Besides the fact that (possibly several) programmers have to work on the sources, and hence the sources should be kept clean in a way anyhow, IMHO documentation tools (like doxygen, or already integrated into the IDE) should be used for the API. They allow a navigation through the sources unburdened from all internal only stuff, so reducing the view onto the essentials. IMHO looking into headers for using a class should not be necessary at all.

Share this post


Link to post
Share on other sites
Quote:
Original post by RDragon1
Where is this 'somewhere' that you read to do that?


in an old thread its quite some time ago,

i will stick with puting them into the same header as the rest of the class thx

Share this post


Link to post
Share on other sites

This topic is 4381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this