[Interest] dynamic_cast failing

Nikos Chantziaras realnc at gmail.com
Sun Apr 12 11:02:03 CEST 2015


On 11/04/15 19:27, René J.V. Bertin wrote:
> On Saturday April 11 2015 18:31:38 Nikos Chantziaras wrote:
>> You might be hitting some undefined behavior. Do your classes have
>> virtual functions? If not, dynamic_cast can fail, as it's only
>> supposed to work with polymorphic classes.
>[...]
> However, your suggestion would cause the dynamic_cast to fail
> everywhere, not just on OS X, right? It seems a bit far-fetched to
> disable virtual destructors on OS X ...

When you get into undefined behavior, then you can't assume that 
something will fail. It might work or it might not. Thiago's suggestions 
are worth investigating (executable formats on different platforms might 
be handling inline virtuals differently, for example, causing this to 
work here but not there.)

However, this is just a possible reason why the code might be failing. 
Your problem might not have anything to do with it. But it just happens 
that many people use multiple inheritance while not being fully aware of 
the intricate details of doing so. You always hear people suggesting 
that you should avoid multiple inheritance because it's very easy to 
shoot yourself in the foot with it.




More information about the Interest mailing list