Yes, provided the ABC (abstract base class) gives an explicit definition elsewhere. An example follows. class Base { public: Base() throw(); virtual ~Base() throw() = 0; }; inline Base::Base() throw() { } inline Base::~Base() throw() { } <-- 1 class Derived : public Base { public: Derived() throw(); }; Derived::Derived() throw() : Base() { } int main() { Derived d; }
Leaving out a definition for Base::~Base() will cause a linker error, because Derived::~Derived() automatically calls Base::~Base() (see FAQ 20.05). In this case, Derived::~Derived() is synthesized by the compiler. Depending on the compiler, there may be a marginal performance benefit in using a pure virtual destructor with an explicit inline definition versus the inline virtual technique that was described in the previous FAQ. Calls to inline virtual functions can be inlined if the compiler is able to statically bind to the class. However, the compiler may also make an outlined copy of an inline virtual function (for any other cases where it isn't able to statically bind to the call). Although in theory destructors of ABCs don't have these limitations, in practice not all compilers produce optimal code when using the inline virtual technique. |