Jump to content
  • Advertisement
Sign in to follow this  
Tanek

filename conflicts - how to name header files? ( c++ )

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

Hello! How should I name my header files? I am used to "Name.ext" from C#. Such as "Vector3.cs, Triangle3.cs" But in C++ there are header file that may have the same name over different projects. Ogre for example solves this by adding the project name infront of the header name. ( "OgreVector3.hpp", "OgreTriangle3.hpp" ) Should I also do this way? Thank you for your opinion and time, Tanek

Share this post


Link to post
Share on other sites
Advertisement
This is a matter of preference, I think. I went from c++ to java and back again currently and I liked the once to one correspondence of java classes with their files. So now I do that with all my c++ classes as well.

Share this post


Link to post
Share on other sites
You could. You could also prefix with one letter instead of a whole word. The best way I've seen is using a subdirectory. This way the include directory contains a subdirectory with the name of the project -- for exampel GL files are usually included like this:

#include <gl/gl.h>

As such any other project could have a 'gl.h' file which would not hurt.

As a side node please note this is only about 'exposed' headers. Header-files internal to your own project only will not obscure headers in other projects because the double quote include searches the local directory first. On the other hand you cannot use the exposed header with the same name from a different project.

But after over 10 years of programming I must say I've only experienced issues with this a few times so perhaps you need to change something else.

Greetz,

Illco

Share this post


Link to post
Share on other sites
You can if you want. If you just keep in mind that you have to give your headers appropriate names you should rarely have much trouble, because most librarys' headers are either in a folder which means you have to include <SDL/SDL.h> or the name of the library prefixes all the filenames, like with Ogre.

Share this post


Link to post
Share on other sites
Thanks! I will do it this way! ( <SDL/SDL.h> )
And yes, I don't prefix classes and functions, but use a namespace.
( well, I use "I" as a prefix for interfaces )

Have a nice day,
Tanek

Share this post


Link to post
Share on other sites
Quote:
Original post by Tanek
Thanks! I will do it this way! ( <SDL/SDL.h> )
And yes, I don't prefix classes and functions, but use a namespace.
( well, I use "I" as a prefix for interfaces )

Have a nice day,
Tanek


Ah, maybe I should have been clear on that I ment don't prefix with library/module name. I use the 'i' && 'c' distinction between interfaces and concrete classes as well as some other light hungerian notation.



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!