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"

Make a class function definition in another .cpp file

I often make a class with many functions/methods inside. The problem is, even if class definition in header file can be relatively small (<100 lines), associated .cpp file can be huge (>500 lines). In normal projects I often split function definitions into many smaller .cpp files. Apparently, I can't do it in Unreal Engine cpp projects. I guess the problem is that I need to convince somehow Makefile (Build.cs file to be specific) that it needs also to build added another .cpp file. How can I do that?


(MyActorA.h file)

 #include "GameFramework/Actor.h"
 #include "MyActorA.generated.h"
 class MYPROJECT_API AMyActorA : public AActor
     void BeginPlay();
     void Tick(float DeltaTime);
     void functionA();


 #include "MyProject.h"
 #include "MyClass.h"
 #include "MyActorA.h"
 AMyActorA::AMyActorA() {
     MyClass *x = new MyClass;
 void AMyActorA::Tick(float DeltaTime) {
 void AMyActorA::BeginPlay() {

Now - when I make void AMyActorA::functionA() definition inside AMyActorA.cpp file or similar AMyActorB.cpp file, everything works. I could of course create auxiliary files with empty actors, but I rather would not choose this option, since it wouldn't really help in organising files. Suppose I created some empty, non-inheriting class in UnrealEngine, like MyClass.h. If I create additional file, like Source.cpp and put definition of MyClass constructor here, I can call it from AMyActorA class (like showed in example above). But, when I put void AMyActorA::functionA() in Source.cpp instead of MyActorA.cpp file, like this:

 #include "MyClass.h"
 #include "MyActorA.h"
 MyClass::MyClass() {
 void AMyActorA::functionA() {

I get the following error:

 Severity    Code    Description    File    Project    Line    Suppression State
 Error    LNK2019    unresolved external symbol "public: void __cdecl AMyActorA::functionA(void)" (?functionA@AMyActorA@@QEAAXXZ) referenced in function "public: virtual void __cdecl AMyActorA::Tick(float)" (?Tick@AMyActorA@@UEAAXM@Z)    C:\UE4 Projects\MyProject\Intermediate\ProjectFiles\MyActorA.cpp.obj    MyProject    1    
Product Version: UE 4.14
more ▼

asked Jan 31 '17 at 05:18 PM in C++ Programming

avatar image

176 17 20 25

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Solution - creating another .cpp file in VS causes creation in Intermediate folder instead of Source/MyProject folder. I had to manually move created item into Source/MyProject file, maybe also to make some small edit in Build.cs file. Now I am able to define functions outside main cpp file.

more ▼

answered Feb 02 '17 at 12:53 PM

avatar image

176 17 20 25

(comments are locked)
10|2000 characters needed characters left
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