Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

best layout for header files? and auto rearrange of cpp file?

This topic is 2840 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

what is the best order to arrange the header file:

private:
protected:
public:

inside of each would it be
variables then funtions??



and also once you have ordered your header file , is there a tool that can reorder your cpp to the same order as the funtions order in the header file..

want to clean up my code as much as possible ?

Share this post


Link to post
Share on other sites
Advertisement
"Best"? It is purely subjective.

I order from public to private, because public is the most interesting 99% of the time you're going to read the code. Private is least interesting, as it should only need to be read when you're fixing bugs.

Functions ahead of variables, for much the same reasons. My variables are almost always private anyway, so they end up at the end of the class file anyway.

Protected should be avoided if possible, it can cause encapsulation issues.

Share this post


Link to post
Share on other sites
Very interesting.

Before I read this I didn't realise protected variables should be avoided. I've had a look around t'internet and it seems that most people say they shouldn't ever really be used. It does make sense though.

Share this post


Link to post
Share on other sites
Quote:
Original post by Monkan
I've had a look around t'internet and it seems that most people say they shouldn't ever really be used. It does make sense though.


I've been told to never use protected data, and instead to always use private data with protected access functions. Is that a good rule?

I use protected quite regularly and never had an issue, but sometimes private has saved me weeks worth of pain when people I didn't know were using the code. Its all about knowing when to use it. Like const, you can't put it on every variable on every function, it should be used where appropriate.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!