Interview Question
Country: India
Yes it was an interview question. And the answer i gave was to put virtual destrucutors in the derived classes and when deleting the object from base pointers; we need to use dynamic_cast to to downcast to correct object and then finally delete the concrete object.
I am not sure what was the intent of this question, was he expecting RTTI or is there any technique.. I am not sure.
But you are right a library of that kind should not be used for inheritance.
I suppose one question would be why you are attempting to extend a class that was not designed for inheritance (or else it would have been given a virtual destructor). I'm sure there may be situations when you might need to do something like that, but are you sure you need to use inheritance here? Is this an interview question?
- eugene.yarovoi December 16, 2012