Problem:
error LNK2019: unresolved external symbol "public: __thiscall Vector3::Vector3(void)" (??0Vector3@@QAE@XZ) referenced in function _WinMain@16
Details:
I have a custom Vector3 class with its basic constructor Vector3() which is declared in the Maths.h file:
struct Vector3
{
float x;
float y;
float z;
Vector3();
...
}
and defined in Maths.cpp:
Vector3::Vector3()
{
this->x = 0;
this->y = 0;
this->z = 0;
}
Module "Maths" is a part of a DLL. As long as I use the Vector3 class within the modules of the DLL it's business as usual. However in the specific case when I try to define it in the executable which links with the DLL, I get unresolved external symbol. E.g.:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
...
Vector3 a = Vector3();
...
}
I have found a workaround. If I perform the definition in the Maths.h itself and ommit it in Maths.cpp entirely, like this:
struct Vector3
{
float x;
float y;
float z;
Vector3()
{
this->x = 0;
this->y = 0;
this->z = 0;
}
...
}
it works. But I have no idea what the problem was and why it manifested itself only in this specific case.