我遇到这种情况:
BaseClass
,其中包含一些纯虚方法DerivedClass
中完全实现此类方法的派生类BaseClass
DerivedClass
BaseClass的定义:
部首:
class BaseClass
{
public:
// ...
virtual DWORD initialize(void) = 0;
virtual DWORD terminate(void) = 0;
};
DerivedClass
的定义:
部首:
class DerivedClass : public BaseClass
{
public:
// ...
DWORD initialize(void);
DWORD terminate(void);
};
CPP:
DWORD DerivedClass::initialize()
{
//...
return 0;
}
DWORD DerivedClass::terminate()
{
//...
return 0;
}
控制台应用程序的作用:
DerivedClass c = DerivedClass();
c.initialize();
return 0;
虽然BaseClass和DerivedClass编译正常(因此链接配置应该很好),但控制台应用程序会编译以下错误:
error LNK2001: unresolved external symbol "public: virtual unsigned long __thiscall DerivedClass::initialize(void)" (?initialize@DerivedClass@@UAEKXZ) unresolved
error LNK2001: unresolved external symbol "public: virtual unsigned long __thiscall DerivedClass::terminate(void)" (?terminate@DerivedClass@@UAEKXZ) unresolved
无法理解为什么DerivedClass没有正确地声明这些虚拟方法?
编辑:控制台应用的Project Properties -> Linker -> Input
字段为:$(OutDir)\base_class.lib;$(OutDir)\derived_class.lib;
,因此从技术上讲,它引用了所有需要的库。