my own RTTI

Started by
24 comments, last by vesoljc 20 years, 2 months ago
@petewood

not sure if i understand u...
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
Advertisement
He''s saying use virtual functions with default definitions instead of RTTI. He has a point. I can really only see using RTTI when you absolutely need the type itself and have to do interesting things with it (such as downcasting to well-defined interfaces in a loose system).
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
please dont use rtti :8

Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
quote:Original post by antareus
He's saying use virtual functions with default definitions instead of RTTI. He has a point. I can really only see using RTTI when you absolutely need the type itself and have to do interesting things with it (such as downcasting to well-defined interfaces in a loose system).


Well, if you were really worried about it, you could put a protected member in the base class that would store the enumeration of that class. Then switch the base class' enumeration (with a getClassType() method):

switch(pBaseClass.GetType()){case TRANSLUCENT_WND:	{		//Render all except the top window		m_Windows.RenderZOrderBackToFrontUntilDepth(1);		break;	}case SLIDER_WND:	{		//Render all except the top window		m_Windows.RenderZOrderBackToFrontUntilDepth(1);		break;	}case FATALITY_WND:	{		//Clear Screen for Window's last moments (MKDA)		m_RenderTarget.Clear();	}defalut: break;}m_Windows.CurrentWindow.CloseAnimation(t_time_stamp);


This kinda alludes to the Abstract Factory Pattern.

[edited by - natasdm on January 26, 2004 9:02:41 AM]
At this address you can find a paper studying the performance of various c++ idioms, like rtti. Basically, typeid should be constant time, and dynamic_cast proportinal to the inheritance tree.

http://anubis.dkuug.dk/jtc1/sc22/wg21/

Bruno
quote:Original post by Anonymous Poster
quote:Original post by Raloth
RTTI is bad design in almost every case. Can''t you come up with some basic class structure instead?


In a lot of cases it''s bad and the needed behavior can probably be handled with some virtual functions, but it''s pretty handy when serializing/deserializing classes to/from a file... you have to know what class to construct when loading, which means you have to save some RTTI info when saving.

Don''t use RTTI just for serialization. Instead just use a generic object factory class to handle this. Much easier and you don''t have to modify pre-existing classes to get it to work.


- Houdini

- Houdini

This topic is closed to new replies.

Advertisement