help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic_cast problem


From: Earl Purple
Subject: Re: dynamic_cast problem
Date: 6 Jul 2006 10:27:37 -0700
User-agent: G2/0.2

Earl Purple wrote:
> I think this has been addressed before but not for 2 years.
>
> I have a model whereby I dynamically load libraries with dlopen then
> verify that they are the correct types with dynamic_cast.
>
> dynamic_cast seems to be failing though with gcc (I am using 3.2.1
> because that is the version we have here that also works with purify).
>
> Whilst I normally don't cast at all in my code, this is the one
> occasion I do - I have built this type of model twice before,
> successfully using Solaris compiler (which has all sorts of other
> problems) and also on VC7 (obviously using LoadLibrary() etc) and it
> worked then.
>
> It is vital I use dynamic_cast because reinterpret_cast would of course
> lead to undefined behaviour if the type is a mismatch.
>
> And because the name of the symbol to be loaded is read from a
> configuration file, there is no possibility of compile-time checks.
>
> Effectively, is it impossible to do object-broking in this manner using
> gcc?

Actually I can follow this up by saying I do dynamic_cast twice and one
of them works but the second one fails.

The first one calls dynamic_cast on the actual object that is retrieved
from dlsym, and that works. This particular object is a generic factory
and creates another object.

I then call dynamic_cast on the 2nd object to check it is the type we
want and at that point it fails (when it shouldn't).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]