 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Fri Aug 11, 2006 10:44 pm Post subject: RTTI How it Works? |
|
|
I have enjoyed explanation #20.4 on FAQ. I was going to ask about how
compiler implements virtual function, but the FAQ tells of that. Great
explanation!
But there is explanation how RTTI work? I search FAQ, but no
explanation for RTTI. Maybe someone can post explanation similar to FAQ
explanation for virtual function, but for RTTI?
FAQ is very good. Maybe RTTI explanation should be at FAQ also.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Aug 14, 2006 6:54 pm Post subject: Re: RTTI How it Works? |
|
|
moleskyca1 (AT) yahoo (DOT) com wrote:
| Quote: | I have enjoyed explanation #20.4 on FAQ. I was going to ask about how
compiler implements virtual function, but the FAQ tells of that. Great
explanation!
But there is explanation how RTTI work? I search FAQ, but no
explanation for RTTI. Maybe someone can post explanation similar to FAQ
explanation for virtual function, but for RTTI?
|
If a class has any virtual functions (or virtual base classes), the
compiler can answer RTTI questions about the same way it handles
virtual functions. If the compiler uses vtables, it can make the
answers to typeid and dynamic_cast accessible through the vtable. For
instance the compiler could have, for every class,
struct foo
{
virtual const type_info& __typeid() const
{
static type_info my_type("foo");
return my_type;
}
};
and every use of the typeid operator on a dynamic object would resolve
to a virtual function call.
The same principle applies to dynamic_cast, but the implementation is a
bit more complex. If a class has N base-class objects, there are about
N*N possible different dynamic_cast situations applicable to the class.
The implementation will want to handle all of those cases in a manner
which is efficient in both space and time, in the compiler, linker, and
at run time.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|