所以,我有一個抽象類Panel
和它MyPanel
的實現。它們看起來與此類似:未解析的外部(抽象類的構造函數/析構函數)
class Panel : public QWidget
{
public:
Panel(QWidget* parent = 0) = 0;
virtual ~Panel() = 0;
// but wait, there's more!!
};
class MyPanel : public Panel
{
public:
MyPanel(QWidget* parent = 0);
~MyPanel() {}; // nothing to do here
};
MyPanel::MyPanel(QWidget* parent) :
Panel(parent)
{
// you must construct additional pylons
}
我得到了鏈接錯誤,從VC++
error LNK2019: unresolved external symbol "public: virtual __thiscall Panel::~Panel(void)" ([email protected]@[email protected]) referenced in function "public: virtual __thiscall MyPanel::~MyPanel(void)" ([email protected]@[email protected]) mypanel.obj
error LNK2019: unresolved external symbol "public: __thiscall Panel::Panel(class QWidget *)" ([email protected]@[email protected]@@@Z) referenced in function "public: __thiscall MyPanel::MyPanel(class QWidget *)" ([email protected]@[email protected]@@@Z) mypanel.obj
爲什麼我會得到這個連接錯誤的構造函數/析構函數?
---答案---
class Panel : public QWidget
{
public:
Panel(QWidget* parent = 0) : QWidget(parent) {};
virtual ~Panel() {};
// but wait, there's more!!
};
我想我在午飯前已經嘗試過這一點。原來我錯了。
它看起來像你有一些錯別字。你能澄清嗎? 類聲明需要以a結尾;例如,類XXX {}; 此外,你有什麼看起來像一個虛擬的構造函數,但這不是在C + + – maccullt 2009-08-19 17:58:01
有效更正我的錯別字,並添加正確的解決方案。 – 2009-08-19 18:03:12
在你的「答案」中你應該明確指出你改變了什麼(基本上通過{}提供空的實現)。否則,它將作爲練習留給讀者來比較您的代碼示例並瞭解不同之處。 – User 2011-07-07 20:33:39