Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   How to find at Runtime, if Created class object is instance of given class declaration (http://www.velocityreviews.com/forums/t452103-how-to-find-at-runtime-if-created-class-object-is-instance-of-given-class-declaration.html)

Ami 02-27-2006 06:48 AM

How to find at Runtime, if Created class object is instance of given class declaration
 
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


Ian Collins 02-27-2006 07:43 AM

Re: How to find at Runtime, if Created class object is instance ofgiven class declaration
 
Ami wrote:
> 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.

Ami 02-27-2006 08:43 AM

Re: How to find at Runtime, if Created class object is instance of given class declaration
 
Thanks a lot Ian for your help. Typeid solves my purpose as required.
Thanks once again.
Regards


Tomás 02-27-2006 04:59 PM

Re: How to find at Runtime, if Created class object is instance of given class declaration
 
Ami posted:

> 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



All times are GMT. The time now is 08:49 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.