This is an interview question:
how can we store the objects of let’s say 3 different classes which are totally independent of each other.
My answer was:
create an array which stores all void pointers.
like :
void *array[];
and store the pointers of all the objects.the array elements can be many.
but for retrieving the elements,i said we can use the dynamic cast or the static cast!
this i think is the wrong answer.i think dynamic cast and static cast are supposed to be used among the classes which are dependent.
please correct me if i am wrong.
if dynamic cast and static cast doesn’t work.May be we can use reinterpret cast.
but is this the correct way to do this task?
Why are you trying to make this so complicated?
If you instead mean that you have an array of objects, and each element can be of any of three distinct, unrelated types, then it’s a silly interview question because it’s a silly thing to do.
(Yes, you would consider
reinterpret_castif forced to employ this approach by limited job opportunities and a pressing need to consume food.)