L160. Getting an error message when using/moving constructor

When I move the UTankAimingComponent() constructor to private:, I get these compile erros:

CompilerResultsLog:Error: Error Tank.cpp.obj : error LNK2019: unresolved external symbol "private: __cdecl UTankAimingComponent::UTankAimingComponent(void)" (??0UTankAimingComponent@@AEAA@XZ) referenced in function "public: static void __cdecl UTankAimingComponent::__DefaultConstructor(class FObjectInitializer const &)" (?__DefaultConstructor@UTankAimingComponent@@SAXAEBVFObjectInitializer@@@Z)
CompilerResultsLog:Error: Error TankAimingComponent.cpp.obj : error LNK2001: unresolved external symbol "private: __cdecl UTankAimingComponent::UTankAimingComponent(void)" (??0UTankAimingComponent@@AEAA@XZ)
CompilerResultsLog:Error: Error BattleTank.generated.cpp.obj : error LNK2001: unresolved external symbol "private: __cdecl UTankAimingComponent::UTankAimingComponent(void)" (??0UTankAimingComponent@@AEAA@XZ)

But if I comment the constructor out completely, the code compiles fine.
Similarly, I tried to create a constructor in the TankMovementComponent, but kept getting similar errors, so I compiled without a constructor.
What could be causing this? (I’m using UE version 4.12.5.)

If the constructor is private that means only functions within the class or friends can call it. Meaning that you wouldn’t be able to just instantiate the class normally.

I get the same errors when I leave the constructor in public:
I have to completely comment the constructor out to get the code to compile…

Wait, I just looked at my code and I have it private. Re-reading the error message again… By any chance did you declare the constructor in the header file and then never defined it in the source file?

It seems to have been the case. I had the constructor definition commented out.
Then I wonder why the code still compiled and the program ran without the constructor. Is the constructor not necessary, then?

If one isn’t provided one will be auto generated by the compiler.

1 Like

Privacy & Terms