I have a base class defined in a dll as below:
class Base
{
public:
virtual void doSomething(); // Definition in cpp
virtual void doSomethingElse() = 0; // May have a definition in cpp
};
In another dll, I derive from Base and implement the necessary methods
class Derived : public Base
{
public:
// Use base implementation for doSomething
void doSomethingElse() override;
}
I am getting linker error unresolved external symbol for Base::doSomething().
From what I understand, since the doSomething() was not overriden, the derived class needs access to the Base::doSomething definition which since I have not exported the Base class explicitly, is unavailable to derived which is in another module.
But why this problem doesn't happen with pure virtual function(it too could have a definition)?
P.S I am using VS2013
But why this problem doesn't happen with pure virtual function(it too could have a definition)?
This would happen only if the pure virtual function of the base class is explicitly invoked. Otherwise, it is not necessary to be implemented.
E.g. Had you implemented Derived::doSomethingElse()
as:
void Derived::doSomethingElse()
{
// Do base class stuff first.
Base::doSomethingElse();
// Then do derived stuff
}
you would have seen the same problem for Base::doSomethingElse
also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With