Skip to main content
GameDev.net gamedev.net
🔒 Locked

RTTI (/GR) embeded information

Started by Axiverse Apr 12, 2005 at 3:49 PM 3 replies 400+ views
Original Post
Axiverse
Axiverse
I know that typeid(...).raw_name is embeded (right?), but will typeid(...) always return the same reference if the same type is put in? Or will typeid(...).name always have the same pointer if they have the same type?
Toolmaker
Toolmaker
The typeid* will always point to the same memory address if both classes are the same type. I use this on alot of places in my code:

if (typeid(CUser) == typeid(*pObject))    // Do stuff


You shouldn't have lots of problems with it.

Toolmaker
 
Fruny
Fruny
Quote:
Original post by Toolmaker
The typeid* will always point to the same memory address if both classes are the same type.


No. It may return type_info objects at different addresses, but that will compare equal. Do not compare typeid results by address.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
MaulingMonkey
MaulingMonkey
Quote:
Original post by Fruny
Quote:
Original post by Toolmaker
The typeid* will always point to the same memory address if both classes are the same type.


No. It may return type_info objects at different addresses, but that will compare equal. Do not compare typeid results by address.


If memory serves, however, each instance of type_info is around "forever", a fact which some dynamic dispatch stuff of the boost library relies on, in the form of:

struct object{    type_info * info;};object o[2];o[0].info = &typeid( int );o[1].info = &typeid( char );assert( *o[0].info != *o[1].info );


Only, using comparisons that actually helped with junk.
Toolmaker
Toolmaker
I made a small mistake with the typeid*. I should have typed type_info. My apologizes for the mistake. :)

Toolmaker
 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.