 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ami Guest
|
Posted: Mon Feb 27, 2006 7:06 am Post subject: How to find at Runtime, if Created class object is instance |
|
|
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
|
Posted: Mon Feb 27, 2006 8:06 am Post subject: Re: How to find at Runtime, if Created class object is insta |
|
|
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
|
Posted: Mon Feb 27, 2006 9:06 am Post subject: Re: How to find at Runtime, if Created class object is insta |
|
|
Thanks a lot Ian for your help. Typeid solves my purpose as required.
Thanks once again.
Regards |
|
| Back to top |
|
 |
Tomás Guest
|
Posted: Mon Feb 27, 2006 5:06 pm Post subject: Re: How to find at Runtime, if Created class object is insta |
|
|
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 |
|
 |
|
|
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
|
|