I have a small C++ project in Visual Studio 2019, but I am getting a linker error in connection with my Mesh.cpp class. I don't really know where it is coming from since all the .obj files exist and can't see what I did wrong in my code. Maybe some of you can point out where I messed up, I'd appreciate every help I can get.
This is the error I am getting:
Error LNK2019 unresolved external symbol "public: __cdecl Mesh::Mesh(float)" (??0Mesh@@QEAA@M@Z) referenced in function "void __cdecl test_function(void)" (?test_function@@YAXXZ)
This is the Test.cpp file where I am getting the linker error when trying to create the Mesh object:
One thing I tried is removing the float argument in the Mesh constructor, so basically changing the constructor to Mesh(); instead of Mesh(float); and passing nothing to it, which worked. But as soon as I put in a parameter that is to be expected, the linker error happens.
You are defining a non-standard, non-member function in Mesh.cpp, you should be defining the constructor you declared in Mesh.h. You don't need to redeclare your class.
With as simple a constructor as you've created you could just inline the definition in the header and not need a separate .cpp source file for the class:
*If you use C++ headers as import modules you should set the project's C++ language standard to compile against /std:c++latest (Preview) instead of /std:c++20.
It certainly won't hurt if you set the project's C++ language standard to Preview status anyway. VS2019/2022 default to C++14.