instanceof

Discussion in 'C++' started by siryuhan@gmail.com, Sep 25, 2005.

  1. Guest

    Is there a C++ equivalent of the Java instanceof keyword?
    , Sep 25, 2005
    #1
    1. Advertising

  2. On 24 Sep 2005 19:26:53 -0700, wrote:

    >Is there a C++ equivalent of the Java instanceof keyword?


    No. But you can emulate its behavior.
    Dave Rahardja, Sep 25, 2005
    #2
    1. Advertising

  3. Phil Staite Guest

    wrote:
    > Is there a C++ equivalent of the Java instanceof keyword?
    >


    If the class has virtual functions (ie. a vtable pointer) you can use
    dynamic_cast<type>() to attempt to cast the pointer to that type. If
    the resultant pointer is NULL, nope, not that type. Non-null, then
    you've got a correctly typed pointer to that kind-of thing.
    Phil Staite, Sep 25, 2005
    #3
  4. benben Guest

    Take a look at RTTI (dynamic_cast, typeof, <typeinfo>, etc)

    Ben
    benben, Sep 25, 2005
    #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. Paul Tomblin

    Re: Dumb instanceof question

    Paul Tomblin, Jul 11, 2003, in forum: Java
    Replies:
    35
    Views:
    1,204
    Manish Jethani
    Jul 27, 2003
  2. Digital Puer

    when to use instanceof?

    Digital Puer, Sep 4, 2003, in forum: Java
    Replies:
    3
    Views:
    4,086
    Roedy Green
    Sep 5, 2003
  3. natG
    Replies:
    8
    Views:
    787
    Roedy Green
    Sep 23, 2003
  4. VisionSet
    Replies:
    13
    Views:
    740
    Dale King
    Nov 18, 2003
  5. Replies:
    21
    Views:
    21,301
Loading...

Share This Page