hi. Group,
C# has a keyword "is" to determine if a object is a given type. Does C++.NET
has something simliar? thanks.
Using C++ run-time type information you can try and cast the object to
an object pointer of the desired type using dynamic_cast<>. If the
resulting pointer is not NULL then the object was (or was derived
from) the specified type.
If you're using MFC there's also the IsKindOf and IsDerivedFrom macros
- provided your class derives from CObject.
Finally, if you want to keep things really simple you could add an
enum member variable to the base class, and assign it's value in the
constructor. Derived classes would assign a different value depending
upon their type, but you can always cast any object to the base class
and call a member function which would return the enum.
i.e (roughly).
enum tagType
{
kBase,
kB,
kC
}
class A
{
A(tag eType) { m_eType = eType; }
A() { m_eType = kBase; }
tagType GetType { return m_eType; }
};
class B : A
{
B() { m_eTyoe = kB; }
};
HTH,
Duncan.