|
-
October 19th, 2004, 05:59 AM
#1
Find out type of class
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");
}
The function I search has another name and other variables, but it finds out, what kind of class the variable (or pointer) is.
I know there is a function like the isClassType() in MFC, but I don`t find it.
Please help.
-
October 19th, 2004, 06:03 AM
#2
Re: Find out type of class
Is typeid what you looking for?
-
October 19th, 2004, 06:06 AM
#3
Re: Find out type of class
MFC: CObject::IsKindOf
Also, take a look at GetClassName API
-
October 19th, 2004, 06:12 AM
#4
Re: Find out type of class
-
October 19th, 2004, 08:00 AM
#5
Re: Find out type of class
 Originally Posted by VictorN
MFC: CObject::IsKindOf
Thanks, that`s it. It`s working fine.
-
October 19th, 2004, 09:49 AM
#6
Re: Find out type of class
 Originally Posted by VictorN
MFC: CObject::IsKindOf
Also, take a look at GetClassName API
What is the connection between CObject::IsKindOf and GetClassName API
Hokutata Yakubotu
-
October 19th, 2004, 09:57 AM
#7
Re: Find out type of class
 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
-
October 19th, 2004, 10:05 AM
#8
Re: Find out type of class
 Originally Posted by Hokutata
What is the connection between CObject::IsKindOf and GetClassName API 
AFAIK, there is no connection between them.
They work independently and return different values/value types.
-
October 19th, 2004, 10:16 AM
#9
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 ]
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|