I am trying to achieve something similar to what is explained here.
I have an Interface class defined as:
class IInterface
{
public:
virtual bool foo() = 0;
virtual void destroy() = 0;
}
And and implementation class defined as:
class MyImplementation : public IInterface
{
MyImplementation();
~MyImplementation();
virtual bool foo();
virtual void destroy() {delete this;}
private:
MyImplementation(MyImplementation const&);
void operator=(MyImplementation const&);
}
extern "C" API MyInterface* __cdecl createMyImplementation();
This works fine in Release mode using VS2010, but in Debug mode, the compiler gives me this error:
MyImplementation.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall IInterface::IInterface(void)" (__imp_??0IInterface@@QAE@XZ) referenced in function "public: __thiscall MyImplementation::MyImplementation(void)" (??0MyImplementation@@QAE@XZ)
What is the problem and how can I fix this ?
From my understanding, we should not have virtual constructors... (see this question).
EDIT:
Fixed typo. foo
does have a body, this is a simplified version of the real code.
Explanation of the why of the destroy function:
http://www.parashift.com/c++-faq-lite/delete-this.html
http://eli.thegreenplace.net/2011/09/16/exporting-c-classes-from-a-dll