can't we use inheritance, virtual destructor and dynamic_cast instead?