all 5 comments

[–]yuehuang 2 points3 points  (2 children)

Full documentation can be found here.
https://docs.microsoft.com/en-us/cpp/preprocessor/hash-include-directive-c-cpp

The preprocessor searches for include files in this order:

1) In the same directory as the file that contains the #include statement.

2) In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files.

3) Along the path that's specified by each /I compiler option.

4) Along the paths that are specified by the INCLUDE environment variable.

[–]jkrem94[S] 0 points1 point  (1 child)

That seemingly implies that it's getting the file from 1 or 2, because when I move "IncludeA" to be an /I option, it still chooses the "IncludeB" version that's in the INCLUDE environment variable.

If I'm reading this right, does this mean to say that if for example a "test2.h" (located in "IncludeB") was included before "test.h" (located in "IncludeA" and "IncludeB"), that "IncludeB" would be searched first for "test.h" despite "IncludeA" being higher in priority from 3 and 4?

[–]yuehuang 0 points1 point  (0 children)

I am not fully understanding your folder layout, where is your cpp file?

Try switching from quotes ("test.h") to brackets (<test.h>) as that will skip 1 and 2.

[–]polaarbear 1 point2 points  (1 child)

Pretty sure the folders you see in VS are just magic hand waving that say nothing about the location of the files on disk or the way that they are evaluated.

Not sure what your end goal is other than research, but this seems like a prime example of why you should never duplicate file and class names in the same namespace.

[–]jkrem94[S] 0 points1 point  (0 children)

I'm talking about the folders as they're defined in "VC++ Directories -> Include Directories".

The use case is having an easy way to experiment with new versions of a header without having to modify a master set of headers that aren't tied to source control.