Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do you define struct functions in a .cpp named differently from declaring .h?

Hi all!

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

Many thanks!

Product Version: UE 4.18
more ▼

asked Apr 29 '18 at 04:01 PM in C++ Programming

avatar image

5 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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!

more ▼

answered Apr 29 '18 at 04:30 PM

avatar image

5 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question