It should normally be defined as an inline virtual function. An example follows. #include <iostream> using namespace std; class Base { public: virtual void f() throw(); virtual void g() throw(); virtual ~Base() throw(); }; void Base::f() throw() { cout << "Base::f()\n"; } void Base::g() throw() { cout << "Base::g()\n"; } inline Base::~Base() throw() { } class Derived : public Base { public: virtual void f() throw(); }; void Derived::f() throw() { cout << "Derived::f()\n"; } int main() { Base b; <-- 1 b.f(); b.g(); Derived d; d.f(); d.g(); }
The reason Base::~Base() is inline is to avoid an unnecessary function call when Derived::~Derived() automatically calls Base::~Base() (see FAQ 20.05). In this case, Derived::~Derived() is synthesized by the compiler. |