[英]error LNK2001: unresolved external symbol C++
在我之前編譯得很好的VC ++代碼中,我添加了一個函數X(),如下所示:
In the file BaseCollection.h
class Base
{
// code
virtual HRESULT X();
//code
};
IN the file DerivedCollection.h
class Derived:public Base
{
HRESULT X();
}
In the file DerivedCollection.cpp
HRESULT Derived::X
{
// definition of Derived here.
}
已將頭文件也正確包含在.cpp文件中。 但我仍然不明白為什么我收到鏈接錯誤:
錯誤LNK2001:未解析的外部符號“public:virtual long __thiscall Base :: X()”(?X @ Base @@ UAEJI @ Z)
我真的很努力地修復這個bug。 任何人都可以幫助我解決這個問題。 非常感謝提前。
你在Base
實現了X()
嗎? 您需要這樣做,或使其成為純虛擬:
class Base
{
// code
virtual HRESULT X() = 0; //pure virtual. Base doesn't need to implement it.
//code
};
此外,您在Derived
對X()
定義看起來是錯誤的。 你可能需要這樣的東西:
HRESULT Derived::X()
{
// definition of Derived here.
}
你永遠不會定義函數X
:
HRESULT Base::X()
{
// definition of X
}
你還需要Derived::X()
的定義,因為它也是virtual
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.