Ruben Campos wrote:
I've recently noticed that it's not allowed to call a pure (non-implemented)
virtual method inside a constructor or a destructor, doesn't matter if this
method is declared in the considered class itself or in one of its base
classes. Such an attempt results in a linker undefined symbol error. Why? Is
it right, or is it a bad issue of my compiler/linker (I'm working with
Microsoft Visual C++ 7.1.3088)? Thank you in advance for your help.
Calling a virtual function in a c-tor or d-tor results in static linking
to that class' member (or the base if this doesn't have it), and not in
a polymorphic call. That's why calling a pure virtual function from the
c-tor or d-tor causes undefined behaviour.
You can provide a definition of the pure virtual function just for that
purpose:
struct ABC {
virtual ~ABC() = 0; // makes this class abstract
};
ABC::~ABC() {} // do nothing, but at least it is defined
struct D : ABC { }; // no problem destroying it -- the ABC's dtor is
// defined, although it is pure
V