Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to find at Runtime, if Created class object is instance of given class declaration

Reply
Thread Tools

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

 
 
Ami
Guest
Posts: n/a
 
      02-27-2006
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

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      02-27-2006
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.
 
Reply With Quote
 
 
 
 
Ami
Guest
Posts: n/a
 
      02-27-2006
Thanks a lot Ian for your help. Typeid solves my purpose as required.
Thanks once again.
Regards

 
Reply With Quote
 
Tomás
Guest
Posts: n/a
 
      02-27-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to find out in which module an instance of a class is created? Johannes Janssen Python 0 08-09-2009 10:06 PM
Object instance "reporting" to a container class instance Daniel Lipovetsky Python 2 03-12-2007 10:35 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
newbie question: how to get the class instance given a module object? Tian Python 4 03-28-2005 09:51 PM



Advertisments