[gameprogrammer] Re: detecting class type at runtime

It really depends on what you are doing. For some cases, double
dispatch might be reasonable. For others, moving the special logic
into the class as a virtual function might be appropriate. In limited
cases, using dynamic_cast<> might be the simplest solution.

Checking for specific subtypes indicates that your design is flawed or
brittle. It can be a symptom of artificial inheritance hierarchies -
if data is different enough to need special treatment, segregate it
entirely. You can still use composition and templates to save yourself
from duplicating logic.

-- Brian

On 18 April 2012 14:09,  <luo_hei@xxxxxxxx> wrote:
> I need to know if variable is of type B or C at runtime, is there some 
> portable way to do this?

To unsubscribe go to http://gameprogrammer.com/mailinglist.html

Other related posts: