p***@gmail.com
2008-05-22 21:38:13 UTC
Hi,
Just checking and I can guess the answer, but what if I have an array
of void*. Into which I put a variety of typed pointer objects.
Normally, when I get out the object, I already know what type it is so
I can static_cast and am safe because it was exactly that same type
when I put it in.
But how powerful and safe is a dynamic_cast in this case. In some
exception handling code, I won't know the original type that I put
in. Can I dynamic_cast from the void* array element to a particular
fully derived type to see if it is that type?
My guess is no, that's not safe and can cause a crash since the
objects are completely hetergenous.
Andy
Just checking and I can guess the answer, but what if I have an array
of void*. Into which I put a variety of typed pointer objects.
Normally, when I get out the object, I already know what type it is so
I can static_cast and am safe because it was exactly that same type
when I put it in.
But how powerful and safe is a dynamic_cast in this case. In some
exception handling code, I won't know the original type that I put
in. Can I dynamic_cast from the void* array element to a particular
fully derived type to see if it is that type?
My guess is no, that's not safe and can cause a crash since the
objects are completely hetergenous.
Andy
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]