Visual Studio 2019 two c++ projects and header file take definitions from another header file from another project [ problem ]

Code Wanderer 396 Reputation points
2021-02-12T11:21:37.677+00:00

I have two c++ console projects inside one solution and I created both XXX.h file on one and second project (different name but same class names). Problem arise when I wanted on first project make method separation from *h.file to *.cpp file. Some functions take deffinitions from second project XXX.h file, because they have same names, which is strange.

I wonder what happened because the first project has no reference to the second project. How to resolve this problem?

I tried rename a file name, change different namespace and reopen solution didn't work. What only work is change class name, or change method names.

I created simple solution with that problem. I add comments to MyClass.h file
https://1drv.ms/u/s!Ahjs_BVflDE3cqqfeZKEA-mbje0?e=5F5d6i

Developer technologies C++
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Guido Franzke 2,191 Reputation points
    2021-02-12T12:37:59.633+00:00

    Hello,
    check the include paths of your projects. Put the headers and cpp files of each project in different directories. Add only the corresponding directory to the project include directory.
    Check that there are no full paths in the #include directives in your source and header files (no #include "C:\path\XXX.h", only #include "XXX.h")
    Regards, Guido


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.