A Bug in project?

The instructor doesn’t include:

APawnTurret::APawnTurret()
{
	// Nothing needed in here.
}

However, without that bit, I get this error and can’t compile.

1>PawnTurret.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl APawnTurret::APawnTurret(void)" (??0APawnTurret@@QEAA@XZ) referenced in function "public: static void __cdecl APawnTurret::__DefaultConstructor(class FObjectInitializer const &)" (?__DefaultConstructor@APawnTurret@@SAXAEBVFObjectInitializer@@@Z)
1>PawnTurret.gen.cpp.obj : error LNK2001: unresolved external symbol "public: __cdecl APawnTurret::APawnTurret(void)" (??0APawnTurret@@QEAA@XZ)
1>D:\Unreal\Projects\ToonTanks\Binaries\Win64\UE4Editor-ToonTanks.dll : fatal error LNK1120: 1 unresolved externals

I only added that bit of code because APawnTank.cpp had it and the error had this bit:
APawnTurret::APawnTurret(void) in the error message above that made me think to add it.

Is that bit needed? Why does the instructors code compile without it?

The lecture commit doesn’t have a constructor declared.

Without the constructor I kept getting the crash posted above. Works great with the constructor.

By crash do you mean compilation error? Crash would mean a runtime error.

If you don’t declare a constructor the compiler generates one for you. If you do then you must define it. So that compilation error means you declared but didn’t define a constructor.

I’ve checked out this lecture’s commit and it does successfully compile.

It was a compilation error. Does Visual Studio 2019 not define a constructor or generate one automatically? Didn’t see one in the lectures video so that is why I was wondering why I had to manually add it when it wasn’t in his video. Well, hopefully no one else has the same issue.

It does, it’s a rule of C++ that the compiler automatically generates them if you don’t declare them. If that stopped working in 2019 that would break a lot of people’s code and no one would be using it.

And as I’ve stated I tested the code and it compiles.

Your first error was probably because you didn’t add the constructor declaration in the .h file whereas the constructor was implemented in the .cpp file

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms