Xyz
BAN USER- 0of 0 votes
AnswersI am given a third-party library with its header to use. Now this library has a class 'Base'. Problem with this class is that it does not have virtual destructor. Now since i don't have the thirds-party code with me i can not do changes over there.
- Xyz in India
I am told to write few derived classes with this and make sure that the object gets cleaned properly when objects are delete. How can we achieve this?| Report Duplicate | Flag | PURGE
C++
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.
Fixed indention in above post!
- Xyz March 31, 2013