How do you define struct functions in a .cpp named differently from declaring .h?
I'm trying to understand how to structure and implement a larger project. As I want to create a multiplayer FPS, the ShooterGame demo project a good place to start.
However, I've become stuck trying to implement one particular set of files from ShooterGame. In the ShooterGame Public folder, there is the file ShooterTypes.h which defines various namespaces and structs which are used by other classes. The struct FTakeHitInfo has a set of functions (constructor and few others) which are subsequently defined in the file TakeHitInfo.cpp in folder Private.
When I try and implement identical files in my own project, the compiler complains that it expected TakeHitInfo.h to be the first file included in TakeHitInfo.cpp. However, no other errors are thrown while editing and going back and forth from declaration to definition, Visual Studio seems to understand that the content in TakeHitInfo.cpp is declared in ShooterTypes.h. But when trying to build the project, it clearly still wants there to be a TakeHitInfo.h file. In ShooterGame, there is no TakeHitInfo header file and the project compiles without error.
Naively, I'm guessed that, within the ShooterGame project there is something that explicitly says "These functions declared in ShooterTypes.h are going to be defined in TakeHitInfo.cpp" but I have searched fruitlessly for any such linkage.
Questions: Does anyone know how exactly this has been implemented within ShooterGame and how such an implementation can be replicated in another project?
Aside-Question (but probably quite important): is it common/reasonable to inact this kind of implementation? i.e. have a bunch of functions defined in a .cpp that has a different name from its .h
Solved my own problem!
I guessed that the problem was that I created the TakeHitInfo file through the Unreal Editor using "Add C++ Class" This created a concurrent header file which I promptly deleted but, somewhere else (???) the project at least thinks that it should exist.
Looking into the source folder for my project, I could still see a TakeHitInfo.h file (which doesn't appear in visual studio) but deleting that alone was insufficient. The compiler still complained that it was expecting a header file.
Deleting TakeHitInfo.cpp, recompiling the project and then creating the file within Visual Studio itself resolved the issue!
Follow this question
Once you sign in you will be able to subscribe for any updates here