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

Started by
5 comments, last by DigitalDelusion 18 years, 8 months ago
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
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.
:: site :: project ::
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
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.
I prefer <project/header.hpp> and don't prefix classes and functions use a namespace.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
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
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.



HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats

This topic is closed to new replies.

Advertisement