RTTI Implementations?

Started by
5 comments, last by redragon 21 years, 1 month ago
Just curious what other people have used for RTTI implementations in the past. I'm thinking of using:
static const char* myObj::m_szType = "myObj";  
or something like that, and using string comparisons to determine the run-time-type, but I'm afraid of the performance issue doing something like that. I'm just curious what other people's experiences have been before I leap into this aspect of the application. Thanks. - sighuh? [edited by - redragon on March 17, 2003 5:01:02 PM]
- sighuh?
Advertisement
No need to make your own RTTI. Use dynamic_cast instead. Works for all classes that have at least one virtual function (or their base class has).
Um, the standard method for RTTI in C++ is dynamic_cast(). typeid() will also work, but I seem to remember reading somewhere that it was less efficient than dynamic_cast() for type equality checking. Read the docs for each of these. Also note that the need for RTTI may indicate a bad design. What are you using this for?

How appropriate. You fight like a cow.

[edited by - sneftel on March 17, 2003 5:33:18 PM]
RTTI is essential under multiple inheritance designs.

Kuphryn
quote:Original post by civguy
No need to make your own RTTI. Use dynamic_cast instead. Works for all classes that have at least one virtual function (or their base class has).

Is this MFC? Or is it standard C++? I'm just curious, because I'm striving for platform independence. I've seen more people implement it on their own, than I've seen this used. This is what prompted the question.


- sighuh?

[edited by - redragon on March 17, 2003 10:39:57 PM]
- sighuh?
quote:Original post by kuphryn
RTTI is essential under multiple inheritance designs.
Kuphryn

Exactly...
Imagine if I have a bunch of objects deriving from CBaseDrawable that represent all my entities in space. I let the user click, grab the elements under the mouse, and filter based on only those objects of a certain type CMonkey objects. Typically dynamic casts (as Kuphryn says) are used when you have multiple inheritance, and are not always indicative of poor design...

- sighuh?
- sighuh?
dynamic_cast and typeid are standard C++

''There''s something out there....something stupid...''
''I think I''m going to be ill. Is that a problem for you?''
''[You] overestimate my conscience by assuming that I have one.''
- Daria

This topic is closed to new replies.

Advertisement