Test types

Hello,

When we want to test types, i know that the "best" way to do so from an OOP aspect is to use polymorphism and make virtual methods ...
But why exactly are test types ( if typeid(thing1) == typeid(thing2)) are potentially bad (as they get tested at the excecution) ?

Thanks!
When we want to test types ...

you do not mention test types for what, so the question is a bit vague. A type can be tested for a whole lot of conditions – to get a short introduction take a look at Section 5.4 “Type Traits and Type Utilities”, The C++ Standard Library (2nd edition), Nicolai Josuttis. Of particular interest might be Table 5.13 “Traits to Check Type Properties” and Table 5.14 “Traits to Check Type Properties of Class Types”
This link also has some other book recommendations: http://www.cplusplus.com/forum/general/212052/
@OP

I wonder if you mean that things like RTTI (eg typeid) and dynamic_cast are often pointers to bad design? As you say it might be better to do virtual polymorphism, or some other solution with templates. So they might not be bad per se, just don't use them to achieve polymorphism.

Perhaps you could share what you exact situation is, there are experts here who can help with that.

Topic archived. No new replies allowed.