typeid , dynamic casting (upcast) and templates

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-05-10T15:10:02Z Indexed on 2010/05/10 15:14 UTC
Read the original article Hit count: 392

Filed under:
|
|

Hello,

I have few questions regarding dynamic casting , typeid() and templates

1) How come typeid does not require RTTI ?

2) dynamic_cast on polymorphic type:

  • When I do downcast (Base to Derive) with RTTI - compilation passes

    When RTTI is off - I get a warning (warning C4541: 'dynamic_cast' used on polymorphic type 'CBase' with /GR-; unpredictable behavior may result)

  • When I do upcast (Derive to Base), with or without RTTI - compilation passes smoothly

What I don't understand is why when I do upcast and RTTI is off - I don't get any warning/error!

3) dynamic_cast on NON polymorphic type:

  • When I do downcast with or without RTTI - compilation fails (error C2683: 'dynamic_cast' : 'CBase' is not a polymorphic type)

BUT

  • When I do upcast with or without RTTI - compilation passes smoothly.

How come on upcast on NON polymorphic type passes w/o RTTI ?

4) Does 'inline' in front of a template function has any effect, i.e. when the compiler compiles the function and see it is 'inline' it will actually treat the function as inline or it is ignored?

Thank you very much for the assistance David

© Stack Overflow or respective owner

Related posts about template

Related posts about dynamic-cast