RTTI

N

Neo

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
 
C

Carlos Martinez

Neo said:
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
 
R

Rolf Magnus

Neo said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top