dimanche 8 mars 2015

c++: When do I require to define a constructor in the header file? [duplicate]



I have the following situation:



**IRenderer.h**
#include "Logger.h"
#include <string>
class IRenderer{
public:
IRenderer(const std::string& name) :_name(name), _logger(name){}
virtual void do() = 0;
private:
std::string _name;
Logger mutable logger;
}


And for classes: MeshRenderer: public IRenderer and ParticleRenderer:public IRenderer my program does not compile anymore if I move the definition of the constructor to a file IRenderer.cpp in which case I get the following LINKER error:



1> MeshRenderer.obj : error LNK2019: unresolved external symbol "public: __thiscall IRenderer::IRenderer(class std::basic_string,class std::allocator > const &)" (??0IRenderer@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall MeshRenderer::MeshRenderer(void)" (??0MeshRenderer@@QAE@XZ)


1>ParticleRenderer.obj : error LNK2001: unresolved external symbol "public: __thiscall IRenderer::IRenderer(class std::basic_string,class std::allocator > const &)" (??0IRenderer@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)


1>E:\Eigene Dokumente\Repositories\shady\Debug\Shady.exe : fatal error LNK1120: 1 unresolved externals



I am especially confused why it is a LINKER error.




Aucun commentaire:

Enregistrer un commentaire