Discussion:
Type testing
(too old to reply)
Atmapuri
2008-06-12 07:33:40 UTC
Permalink
Hi!

How do I write in C++:

Is MyVar of MyType

to get a a boolean answer? I would like to test this
for TObject descendants and for other types in C++.

Thanks!
Atmapuri
Christian PANEL
2008-06-12 08:57:28 UTC
Permalink
typeid(MyVar) == typeid(MyType)
Post by Atmapuri
Hi!
Is MyVar of MyType
to get a a boolean answer? I would like to test this
for TObject descendants and for other types in C++.
Thanks!
Atmapuri
Atmapuri
2008-06-12 10:42:28 UTC
Permalink
Hi!

I need something else because in watches I get
error: RTTI not available for expression evaluation.

Thanks!
Atmapuri
Post by Christian PANEL
typeid(MyVar) == typeid(MyType)
Post by Atmapuri
Hi!
Is MyVar of MyType
to get a a boolean answer? I would like to test this
for TObject descendants and for other types in C++.
Thanks!
Atmapuri
Remy Lebeau (TeamB)
2008-06-12 16:20:52 UTC
Permalink
Post by Atmapuri
Is MyVar of MyType
to get a a boolean answer?
Use dynamic_cast, ie:

if( dynamic_cast<MyType>(MyVar) != NULL )
...
Post by Atmapuri
I would like to test this for TObject descendants
and for other types in C++.
dynamic_cast only works with polymorphic types that have RTTI attached to
them.


Gambit

Loading...