RTTI

Discussion in 'C++' started by Neo, Aug 1, 2006.

  1. Neo

    Neo Guest

    Hi Friends,
    I have a question about RTTI.
    1) In C++ we have vptr pointing to vtables which helps to make use of
    pointer as polymorphic entities.
    2) Without knowing object type I can call methods of object using
    those pointers.
    So in which case RTTI is needed? ( Why I need to know my object
    type?)

    Regards,
    Neo
     
    Neo, Aug 1, 2006
    #1
    1. Advertising

  2. Neo wrote:
    > Hi Friends,
    > I have a question about RTTI.
    > 1) In C++ we have vptr pointing to vtables which helps to make use of
    > pointer as polymorphic entities.
    > 2) Without knowing object type I can call methods of object using
    > those pointers.
    > So in which case RTTI is needed? ( Why I need to know my object
    > type?)
    >
    > Regards,
    > Neo
    >


    For example: safe downcasting of polimorphic types

    dynamic_cast uses RTTI
     
    Carlos Martinez, Aug 1, 2006
    #2
    1. Advertising

  3. Neo

    Rolf Magnus Guest

    Neo wrote:

    > Hi Friends,
    > I have a question about RTTI.
    > 1) In C++ we have vptr pointing to vtables which helps to make use of
    > pointer as polymorphic entities.


    We might. The C++ standard doesn't mandate any specific way of implementing
    polymorphism. vtables are just the typical implementation.

    > 2) Without knowing object type I can call methods of object using
    > those pointers.


    As long as your pointer points at least to a base class.

    > So in which case RTTI is needed? ( Why I need to know my object
    > type?)


    If you have a member function in a derived class that doesn't make sense for
    the base or any other derived classes.
     
    Rolf Magnus, Aug 1, 2006
    #3
  4. Neo

    Neo Guest

    Carlos Martinez wrote:
    > Neo wrote:
    > > Hi Friends,
    > > I have a question about RTTI.
    > > 1) In C++ we have vptr pointing to vtables which helps to make use of
    > > pointer as polymorphic entities.
    > > 2) Without knowing object type I can call methods of object using
    > > those pointers.
    > > So in which case RTTI is needed? ( Why I need to know my object
    > > type?)
    > >
    > > Regards,
    > > Neo
    > >

    >
    > For example: safe downcasting of polimorphic types
    >
    > dynamic_cast uses RTTI


    Thanks to all for your inputs..
     
    Neo, Aug 2, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Harrison

    Re: RTTI

    John Harrison, Jul 14, 2003, in forum: C++
    Replies:
    2
    Views:
    452
    John Harrison
    Jul 14, 2003
  2. Alf P. Steinbach

    Re: RTTI

    Alf P. Steinbach, Jul 14, 2003, in forum: C++
    Replies:
    0
    Views:
    467
    Alf P. Steinbach
    Jul 14, 2003
  3. Steven Lien

    About RTTI

    Steven Lien, Aug 19, 2003, in forum: C++
    Replies:
    4
    Views:
    601
    Ivan Vecerina
    Aug 19, 2003
  4. BillyO
    Replies:
    2
    Views:
    490
    dslater
    Sep 30, 2003
  5. tirath
    Replies:
    3
    Views:
    710
    Ivan Vecerina
    Oct 12, 2003
Loading...

Share This Page