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

Discussion in 'C++' started by Ami, Feb 27, 2006.

  1. Ami

    Ami Guest

    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
     
    Ami, Feb 27, 2006
    #1
    1. Advertising

  2. Ami

    Ian Collins Guest

    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.
     
    Ian Collins, Feb 27, 2006
    #2
    1. Advertising

  3. Ami

    Ami Guest

    Thanks a lot Ian for your help. Typeid solves my purpose as required.
    Thanks once again.
    Regards
     
    Ami, Feb 27, 2006
    #3
  4. Ami

    Tomás Guest

    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
     
    Tomás, Feb 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MrB
    Replies:
    2
    Views:
    433
    =?Utf-8?B?Tmljaw==?=
    Jan 26, 2004
  2. Lord0
    Replies:
    1
    Views:
    599
    Thomas Weidenfeller
    Apr 19, 2006
  3. Tian
    Replies:
    4
    Views:
    341
    Kent Johnson
    Mar 28, 2005
  4. Chris Rebert
    Replies:
    0
    Views:
    433
    Chris Rebert
    Jun 11, 2009
  5. Johannes Janssen
    Replies:
    0
    Views:
    280
    Johannes Janssen
    Aug 9, 2009
Loading...

Share This Page