Is it possible to use RTTI in a dynamic library ?
JOLY Loic
loic.joly@renault.com
Mon Nov 17 16:08:00 GMT 2003
The problem is under a Linux platform with gcc-3.2.2.
We've got an header containing the following (simplified):
class A
{
public:
virtual bool fred1();
};
class B : public A
{
public:
virtual bool fred2();
};
Included in a .so file (a dll in Windows terms)
and Included in an application
The .so file is loaded in a dynamic way: dlopen, dlsym, dlclose
(LoadLibrary, GetProcAddress) and returns pointers to A objects.
What we want to do in the main application:
A *a = getFromSoFile(); // I'm sure this is a pointer to B in the real life
B *b = dynamic_cast<B *>(a);
--> The result is b == NULL;
Of course typeid(a) != typeid(B *)
but the strings returned by typeid(a).name() and typeid(B *).name() are
equal.
Is there any way to make to make it work ? If we put everything directly
in the program (no .SO file) it works as intended.
--
Loïc
More information about the Gcc-help
mailing list