C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to find at Runtime, if Created class object is instance

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Ami
Guest





PostPosted: Mon Feb 27, 2006 7:06 am    Post subject: How to find at Runtime, if Created class object is instance Reply with quote



Hi All,
I want to find at runtime for given class object, if it is a object
of given class. For example:
I have declared "ClassA" and i have created its instance "instA". Now
at run time, how can i detect, if "instA" is object of "ClassA".
Something like "is" operator in Delphi or C#. (e.g if( instA is ClassA)
)

Thanks in advacne.
Regards
Back to top
Ian Collins
Guest





PostPosted: Mon Feb 27, 2006 8:06 am    Post subject: Re: How to find at Runtime, if Created class object is insta Reply with quote



Ami wrote:
Quote:
Hi All,
I want to find at runtime for given class object, if it is a object
of given class. For example:
I have declared "ClassA" and i have created its instance "instA". Now
at run time, how can i detect, if "instA" is object of "ClassA".
Something like "is" operator in Delphi or C#. (e.g if( instA is ClassA)
)

Look up typeid().


--
Ian Collins.
Back to top
Ami
Guest





PostPosted: Mon Feb 27, 2006 9:06 am    Post subject: Re: How to find at Runtime, if Created class object is insta Reply with quote



Thanks a lot Ian for your help. Typeid solves my purpose as required.
Thanks once again.
Regards
Back to top
Tomás
Guest





PostPosted: Mon Feb 27, 2006 5:06 pm    Post subject: Re: How to find at Runtime, if Created class object is insta Reply with quote

Ami posted:

Quote:
Hi All,
I want to find at runtime for given class object, if it is a object
of given class. For example:
I have declared "ClassA" and i have created its instance "instA". Now
at run time, how can i detect, if "instA" is object of "ClassA".
Something like "is" operator in Delphi or C#. (e.g if( instA is ClassA)
)

Thanks in advacne.
Regards

You always know the type of a variable/object -- just looks at its
definition.

If you're dealing with classes and inheritence, maybe take a look at
"dynamic_cast".

-Tomás
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.