0

I am currently trying to inherit from a c++ interface defined as such:

class IWindow: public Initializable
{
public:
    virtual ~IWindow(void) =0;

    virtual BOOL IsVisible(void) =0;
    virtual void Show(BOOL inbShow) =0;
};

This interface is defined in a separate project from the class which is trying to inherit from it. That class is defined as such:

#include "IWindow.h"

class Win32Window: public IWindow
{
    HGLRC m_renderingContext;
    HWND m_win32Handle;
    HDC m_deviceContext;

    BOOL m_bVisible;
public:
    Win32Window(void);
    virtual ~Win32Window(void);

    virtual void Initialize(void);
    virtual void Destroy(void);

    virtual BOOL IsVisible(void);
    virtual void Show(BOOL inbShow);
};

I am getting an external symbol issue on the publicly defined pure virtual constructor of IWindow the exact error message reads:

1>Win32Window.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall IWindow::~IWindow(void)" (??1IWindow@@UAE@XZ) referenced in function "public: virtual __thiscall Win32Window::~Win32Window(void)" (??1Win32Window@@UAE@XZ)

I cannot seem to understand why this error is occuring as far as I was aware whether or not a class is in another project should not matter as long as the file is #included into the inheriting class's header file. Can anyone explain this error to me and possibly provide a solution to this error? I eventually plan to have the class IWindow as part of a dll but until then I need to be able to compile and test this solution with the files within multiple different projects.

teddy
  • 171
  • 1
  • 1
  • 12

1 Answers1

2

You have an error message about undefined pure virtual destructor.

A destructor, even if it's pure virtual, must have an implementation. Most likely a .cpp file with implementation of the IWindow::~IWindow() is not included into the project. That's why linker cannot find it.

nullptr
  • 11,008
  • 1
  • 23
  • 18
  • so even if its pure virtual it still needs an implementation? Is this specific to pure virtual destructors? – teddy Jun 16 '13 at 21:36
  • Yes, it is specific to destructors. A destructor is always called, even if it's pure virtual. If you instantiate an object of class which has pure virtual destructor, or of any of its derived classes, you must define a destructor, otherwise the object cannot be destroyed. You can find lots of discussions on the topic by searching 'pure virtual destructors'. – nullptr Jun 16 '13 at 21:38
  • @juanchopanza In case of destructor, it's not sufficient to implement it in a derived class. – nullptr Jun 16 '13 at 21:39
  • @juanchopanza It's defined in standard. See the second comment at http://stackoverflow.com/questions/630950/pure-virtual-destructor-in-c – nullptr Jun 16 '13 at 21:41
  • Ah yes, I'd forgotten all about that. Thanks for the link. – juanchopanza Jun 16 '13 at 21:44