[Interest] dynamic_cast failing

Thiago Macieira thiago.macieira at intel.com
Sat Apr 11 19:43:14 CEST 2015


On Saturday 11 April 2015 17:08:45 René J.V. Bertin wrote:
> Hi,
> 
> I have an issue with some KDE4 code (built against Qt 4.8.6) where a
> dynamic_cast fails on OS X but not on Linux (be it with gcc or clang
> 3.5). In a nutshell:
> 
> class D: public class C, public class B, public class A;

Without concrete code it's difficult to be sure, but the usual suspect in this 
kind of problem is the same: your virtual tables are not properly anchored in 
shared libraries.

Make sure that all classes participating in this party check all these boxes:
 * have an export macro in the class declaration
 * the primary virtual function is in a .cpp, NEVER inline

The primary virtual function is the first newly overriden function in the 
parent classes' order or, if none are overridden, the first new virtual. 
Usually, polymorphic classes have virtual destructors and destructors are 
always overridden, so this is your best bet.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list