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'
任何想法/建议?好像我需要重载/覆盖Add&amp; amp;正确删除基类中的函数。
答案 0 :(得分:2)
您已声明了PictureWidget的析构函数,但尚未提供实现。
也许这阻止了编译器正确生成vtable或类似导致错误消息的东西。我真的不知道。
但无论如何都是一个问题。