how to get variable type
-
yes i am using vc++6.0 i will try the typeid method once i re-write all my lost codes :| My initial intention was to come up with a global class that can convert a variable of type A to type B at run-time.
What vc 7.x is doing seems more logical than vc 6.0 ... it seems to be checking the "from" and "to" types! class A { int a; }; class B: public A { int b; }; /***** break ****/ B b; if (dynamic_cast**(&b)) { printf("OK"); } /***** above will work in vc 7.x but not vc 6.0 */ /***** below will NOT work in both vc 7.x & vc 6.0 */ B b; A *p_a = &b; if (dynamic_cast**(p_a)) { printf("OK"); }****
-
is it possible to check a variable's type? e.g. if m_variable is equal to CString, DoSomething()...
-
is it possible to check a variable's type? e.g. if m_variable is equal to CString, DoSomething()...
For non RTTI way You could try
IsKindOf
(Of course, this is not as good as RTTI. As this was invented by Microsoft before the time where RTTI was approved by ANSI.) For RTTI you could try type_info or the one they mentiond dynamic_cast.. Sonork 100.41263:Anthony_Yio Life is about experiencing ... -
is it possible to check a variable's type? e.g. if m_variable is equal to CString, DoSomething()...
For MFC objects, have you looks at
IsKindOf()
?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)