Each of these classes are in separate dll modules:
class Base
{
public:
virtual void foo();
void bar();
};
class Derived : public Base
{
public:
// override Base::foo()
void foo();
};
In Other.cpp:
#include "Derived.h"
The module that contains Derived links with Base.lib (not shown are the export/import directives). The module that contains Other.cpp links with Derived.lib, but not Base.lib. Up to this point, everything works fine.
However, if I change Base::bar() to be virtual and do not make a change to Derived, then the linker complains when linking Other.dll:
Other.obj : error LNK2001: unresolved external symbol "publi开发者_JAVA百科c: virtual void __thiscall Base::bar()" ...
The only solutions I have found is to override Base::bar() in Derived or to have Other.dll also link with Base.lib. Both solutions are not desired because they add client requirements when the server changes.
Any ideas on a better way to access/define the base class virtual methods in this scenario?
What's happening is that virtual Base::bar
needs to be in the vtable of a Derived, since there's no Derived::bar
.
I don't understand your comment about "client requirements when the server changes". I don't see how base/derived maps to client/server. They're two independent dimensions to me.
精彩评论