Re: Find out type of class
Is typeid what you looking for?
Re: Find out type of class
MFC: CObject::IsKindOf
Also, take a look at GetClassName API
Re: Find out type of class
Re: Find out type of class
Quote:
Originally Posted by VictorN
MFC: CObject::IsKindOf
Thanks, that`s it. It`s working fine. :wave:
Re: Find out type of class
Quote:
Originally Posted by VictorN
MFC: CObject::IsKindOf
Also, take a look at GetClassName API
What is the connection between CObject::IsKindOf and GetClassName API :confused:
Re: Find out type of class
Quote:
Originally Posted by je-wo
How do I find out, which type of class the variable is, I catually have.
Let me give you an example how I mean this:
Code:
CRectangle* rectangle = new CRectangle();
if ( isClassType(CRectangle, rectangle) )
{
print("the variable rectangle is a CRectangle class");
}
Anytime you need to code like this, think about how you've designed the program. More often than not, there is a flaw in your design.
In C++, you have virtual functions, and the need for doing this is for the most part, unnecessary.
Regards,
Paul McKenzie
Re: Find out type of class
Quote:
Originally Posted by Hokutata
What is the connection between CObject::IsKindOf and GetClassName API :confused:
AFAIK, there is no connection between them.
They work independently and return different values/value types.
Re: Find out type of class
As Paul pointed out, C++ was deliberately designed (originally) to NOT provide run-time type identification. Later versions of the language do support RTTI (it is necessary internally for dynamic_cast). The MFC classes (derived from CObject) have their own methodology. COM classes have a different methodogy.
Think (and think again) if you really need to make use of any of the available methods. At the very least it will potentially decrease the portability of your code if you use them [actually if you do use MFC or COM you have already reduced the portability of your code :D ]