L
lallous
Brian Genisio said:I know I have done this in Java, but is there a way to do it in C++?
Type B and C inherit from type A.
In a function, I want to check an instance of A (which can also be B or
C), to see what it is, and move on... something like:
A something;
if( A.typeof(B) )
{
B somethingB = static_cast<B>(something);
// Do things with the B members
}
else if ( A.typeof(C) )
{
C somethingC = static_cast<C>(something);
// Do things with the C members
}
else
{
// Do things with the A members
}
I know I can accomplish something similar with virtual functions
(polymorphism), but can the above be done in any way?
Just curious.
Brian
Refer to the 'typeid' operator.