1

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?

user3075425
  • 332
  • 1
  • 6
  • 23

3 Answers3

1

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

Nikos Athanasiou
  • 29,616
  • 15
  • 87
  • 153
0

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.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
0

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350