C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RTTI How it Works?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Fri Aug 11, 2006 10:44 pm    Post subject: RTTI How it Works? Reply with 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?

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






PostPosted: Mon Aug 14, 2006 6:54 pm    Post subject: Re: RTTI How it Works? Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.