I have including problems in a C++ Project. I included math.h, but there are strange problems with my vector.h and my matrix.h header files. Am I allowed to call these files vector.h and matrix.h?
-
2Did you try using `#include ""` syntax instead of `#include <>`? – Alex Telishev Feb 05 '14 at 18:53
-
Not for math.h, but for the other header files I created. – user3075425 Feb 05 '14 at 18:55
-
what errors do you get? – Natan Streppel Feb 05 '14 at 18:58
-
For example on vector.h I get errors like "Vector3 is not a type name" but in vector.cpp everything is fine... This error pops up randomly, like a 1:2 chance. Thats why I think its an including error – user3075425 Feb 05 '14 at 19:02
-
could you please add the error message to the post? – Creris Feb 05 '14 at 19:04
3 Answers
Two headers cannot have the same name.
By same name, the full path name is implied, so
#inlcude "testClass.h"
#include "heders/testClass.h" // OK, distinguishable
Visual studio prevents you from adding a header having a name that already exists in the project.
You should also check that your header is actually included in your project (or through your Makefile, build system etc). A quick check would be to cause a syntactic error in that header and see if it breaks the build
So to get back to your question, do you already have headers called vector.h and matrix.h? Cause that would be the only thing preventing you from naming new headers like that. Keep in mind that headers accessed with #include <...> require their folder to be set as an include (external) directory so qualifying up to that path won't work

- 29,616
- 15
- 87
- 153
In theory I don't know of anything to prohibit doing so.
I'd consider vector.h
close enough to <vector>
that using it would be a poor idea.
I'm not exactly excited about matrix.h
either, but at least it's not nearly so obviously a poor choice.
Of course, for any header you wrote yourself (rather than one provided by the tools you're using) you want to enclose the name in quotes, not angle brackets.

- 476,176
- 80
- 629
- 1,111
The rationale why C++ chose the unusual <vector>
format without suffix is because the intent was to remain compatbile with existing C code which might very well have "vector.h"
. So the answer is yes, by design.

- 173,980
- 10
- 155
- 350