Boris wrote: > [crossposted to gnu.g++.help] > > Boris wrote: > > Boris wrote: > >> [...] The code I talk about looks like this: > >> > >> if (typeid(b) == typeid(level2)) > >> { > >> const level1 *l1 = dynamic_cast<const level1*>(&b); > >> } > > > > I changed the code for testing purposes and replaced dynamic_cast with > > reinterpret_cast - this works. > > > > I changed then the code to make it look like this: > > > > if (typeid(b) == typeid(level2)) > > { > > const level2 *l2 = dynamic_cast<const level2*>(&b); > > const level1 *l1 = l2; > > } > > > > This works, too. Is there any other possible explanation than a > > compiler bug why a dynamic_cast<const level1*> should not work?
Why not just: if(level2 const* l2 = dynamic_cast<level2 const*>(&b)) { // no need comparing typeinfo's } ? > > It looks like a problem with g++. The code I was talking about is in a > shared library. When I link the executable statically dynamic_cast works. > When I use however the shared library dynamic_cast returns 0. Same code but > different behavior due to linking. > > There is a section "dynamic_cast, throw, typeid don't work with shared > libraries" at http://gcc.gnu.org/faq.html#dso. I wonder how you reached such a conclusion. Where on that page do they say it does not work? _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus