How do i move .h and .cpp files in Visual Studio


I’m a new programmer, trying to learn some Unreal Engine game development. But now I encounter, a presumably basic issue, that i’m not able to resolve via existing questions on this website and others. Hence the question: What is the problem? and how do I solve this?

I wanted to reorganise my .h and .cpp file (“Item.h” and “Item.cpp”). The original structure was as follows:

Old structure

The desired end result includes extra folders inbetween.

Desired result

I already experienced that simply moving the files in the solution explorer does not actually move the files on the computer, and as such doesn’t cause any problems, but neither fulfills my desires.

Then I tried moving the files in my computer’s file explorer. Which led to VS not finding my files. Online (Visual Studio move project to a different folder) I read that a possible solution would be to remove the .h and .cpp files from the VS solution explorer, then move them to the appropriate location on my computer, and then add them again via the solution explorer. After trying this I end up with many warnings in the code.

Warnings

Now my best guess would be that the relocated files are missing the correct link with the the includes, or the pathing has to be manually updated somehow. A comment on a different thread indicates this may be the case:

“Unload all the dependent projects from the solution, before removing the project you want to move. That way, they don’t detect the removal and the project references stay intact. After you move the project and re-add it to the solution, you can load the dependent projects again. –base2 Commented Nov 30, 2011 at 11:25”

Ofcourse I didn’t unload all the dependent projects before removal… So maybe this is my problem?

So my questions are:
What is the problem? and how would I solve this?

(Edit 10-10-2024 20.40)
The previously stated comment by “base2” doesn’t work for me

I found that its the “includes” that lead to the errors. If I specify the entire path of the required header files almost everything is working again. Unfortunately I believe Unreal Engine generates a file (in my case called: Item.generated.h) which cannot be found by me or visual studio. So i cant re-add all the file paths required. Hence i still don’t know how to “repair” the damage.

Leave a Reply

Your email address will not be published. Required fields are marked *