This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Need help with dynamic_cast across shared libraries with gcc 3.2.3.
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: "Yuly Novikov" <novikov_yuly at hotmail dot com>, gcc at gcc dot gnu dot org, gcc-help at gcc dot gnu dot org
- Cc: novikov_yuly at hotmail dot com
- Date: Thu, 17 Jul 2003 09:43:21 -0500
- Subject: Re: Need help with dynamic_cast across shared libraries with gcc 3.2.3.
Hi Yuly,
>Is there any other way to make the algorithm above work with gcc 3.2.3?
If you KNOW the pointer is the given type, use a reinterpret_cast<foo*>(ptr) instead of a dynamic_cast<foo*>(ptr). And put a BIG disclaimer in your source code saying "This is correct. All your {derived class pointer name} are belong to us."
Also note: if you use those kinds of objects for exceptions in your across-shared-library boundaries, you'll probably run into situations where your code fails to catch the object. The dynamic_cast mechanism uses the same RTTI information that the exception handling's catch mechanism uses. And, similiarly, you'll probably experience problems using the RTTI mechanism if you use typeid and type_info.
HTH,
--Eljay
PS: you shouldn't need to dynamic_cast the derived pointer to the base pointer type. A derived pointer IS-A base pointer, already.