Archived

This topic is now archived and is closed to further replies.

redragon

RTTI Implementations?

Recommended Posts

redragon    122
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]

Share this post


Link to post
Share on other sites
civguy    308
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).

Share this post


Link to post
Share on other sites
Sneftel    1788
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]

Share this post


Link to post
Share on other sites
redragon    122
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]

Share this post


Link to post
Share on other sites
redragon    122
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?

Share this post


Link to post
Share on other sites
masonium    118
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

Share this post


Link to post
Share on other sites