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

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

## 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 on other sites
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 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 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 on other sites
I prefer <project/header.hpp> and don't prefix classes and functions use a namespace.

##### 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 on other sites
Quote:
 Original post by TanekThanks! I will do it this way! ( )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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634110
• Total Posts
3015558
×