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

A

Ami

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
 
I

Ian Collins

Ami said:
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().
 
A

Ami

Thanks a lot Ian for your help. Typeid solves my purpose as required.
Thanks once again.
Regards
 
T

Tomás

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top