I checked multiple other posts and this must work. This code below must be correct.
I am simply declaring the class in .h and .cpp with a constructor that sets one parameter in the same line.
Why the compiler complains in the error below?
.h
#ifndef WOOD_ELEMENT_H
#define WOOD_ELEMENT_H
class element
{
int id = -1;
public:
element(int _id);
};
#endif
cpp
#include "wood_element.h"
element::element(int _id) : id(_id)
{
// ...
}
Error:
3>wood_main.obj : error LNK2019: unresolved external symbol "public: __cdecl element::element(int)" (??0element@@QEAA@H@Z) referenced in function "public: class element * __cdecl std::vector<clas
s element,class std::allocator<class element> >::_Emplace_reallocate<int &>(class element * const,int &)" (??$_Emplace_reallocate@AEAH@?$vector@Velement@@V?$allocator@Velement@@@std@@@std@@QEAA
PEAVelement@@QEAV2@AEAH@Z) [C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\compas_wood\build_win\wood.vcxproj]
3>C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\compas_wood\build_win\Release\wood.exe : fatal error LNK1120: 1 unresolved externals [C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\compas_wood
\build_win\wood.vcxproj]