I am pretty sure that doesn't work ... it won't dynamic cast from something 
that isn't an object 'cuz if it doesn't optimize it away, it does it using a 
virtual function at run-time ...

"Simon Buchan" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Chris Shearer Cooper wrote:
>> Using gcc version 3.2 ...
>>
>> The compiler likes to optimize away calls to dynamic_cast - so, for 
>> instance, if I do this :
>> class Base { ... }
>> class Derived : public Base { ... }
>> Base b;
>> Derived *d = dynamic_cast<Derived*>((Derived*)&b);
>> (yes, that's a stupid thing to do, it's just that to explain the real 
>> issue would take more pages than you want to read)
>> That code happily sets d to &b because the compiler says "Hum, I've been 
>> given a Derived*, obviously that's the same as a Derived*, so I can just 
>> turn the dynamic_cast into a static_cast."
>>
>> Is there a way to disable this particular optimization?
>>
>> Thanks!
>> Chris
> You could try going through a void*?
>
>
> 


_______________________________________________
Help-gplusplus mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to