I l @ ve RuBoard |
Answer 21-1: Remember that destructors are called in the order derived class first, then base class. In this case, the destructor for the derived class, list_of_integers , is called to destroy the class. The class is gone. Next, the destructor for the base class list is called. It calls the function clear . This is a pure virtual function, so C++ must call the clear function in the derived class. But the derived class isgone. There is no clear function. This makes C++ very upset and it aborts the program. (Actually, only good compilers will cause a program to abort. Others may do something really strange to your program.) You should never call pure virtual functions from a destructor. Actually, be very careful when you call virtual functions of any type in a destructor. |
I l @ ve RuBoard |