C++ 在多级继承的情况下对 vtable 的未定义引用

C++ Undefined reference to vtable in case of multi-level inheritance

class Widget
{
public:
    Widget(int x, int y, int width, int height):
        m_X(x),
        m_Y(y),
        m_width(width),
        m_height(height)
    {
    }
    virtual ~ Widget()
    {
        m_widgetList.clear();
    };
    virtual void AddWidget(Widget * wget)
    {
        m_widgetList.push_back(wget);
    }
    virtual void RemoveWidget(Widget * wget)
    {
        m_widgetList.remove(wget);
    }
    virtual void DebugInfo() { };
private:

    int m_X;
    int m_Y;
    int m_width;
    int m_height;

private:
    std::list<Widget*> m_widgetList;

};

class PanelWidget: public Widget
{
public:
    PanelWidget(int x, int y, int width, int height)
        : Widget(x, y, width, height)
    {

    }
    virtual ~PanelWidget()
    {

    }

    virtual void DebugInfo() { };
};

class PictureWidget: public PanelWidget
{
public:
    PictureWidget(std::string imageFileName, int x, int y, int width, int height)
        : PanelWidget(x, y, width, height),
          m_imageFileName(imageFileName)
    {

    }
    virtual ~PictureWidget();

    virtual void DebugInfo() { };

private:
    std::string m_imageFileName;

};


int main (int argc, char* argv[])
{

    Widget* mainScreen = new PanelWidget(0, 0, 800, 600);

    mainScreen->AddWidget( new PictureWidget("background.jpg", 0, 0, 800, 600));

    mainScreen->AddWidget( new PictureWidget("icon.jpg", 10, 10, 50, 50) );


    delete mainScreen;
}

出现未定义的引用错误:

In function `main':
undefined reference to `vtable for PictureWidget'
undefined reference to `vtable for PictureWidget'

有ideas/suggestions吗?似乎我需要 overload/override 基础 class 中的添加和删除功能正确。

您已声明 PictureWidget 的析构函数但尚未提供实现。

也许这会阻止编译器正确生成其 vtable 或导致错误消息的类似情况。我真的不知道副手。

但这无论如何都是个问题