RTTI typeinfo pointers

Discussion in 'C++' started by Asfand Yar Qazi, Jun 1, 2004.

  1. Hi,

    Will the std::type_info object returned by typeid be the same
    object every time it is called for a given type?

    Can there ever be a chance that a std::type_info object returned
    by typeid for two different types will share the same memory
    address? Lets say, for example, I want to use the address of the
    type_info object as a hash value.

    Thanks,
    Asfand Yar


    --
    http://www.it-is-truth.org/
    Asfand Yar Qazi, Jun 1, 2004
    #1
    1. Advertising

  2. Asfand Yar Qazi

    tom_usenet Guest

    On Tue, 01 Jun 2004 16:35:11 +0100, Asfand Yar Qazi
    <im_not_giving_it_here@i_hate_spam.com> wrote:

    >Hi,
    >
    >Will the std::type_info object returned by typeid be the same
    >object every time it is called for a given type?


    No (specifically on Windows with a type defined both in a .exe and a
    ..dll), and the standard doesn't require it. The objects must compare
    equal though, of course.

    >
    >Can there ever be a chance that a std::type_info object returned
    >by typeid for two different types will share the same memory
    >address?


    No, it wouldn't be conforming.

    > Lets say, for example, I want to use the address of the
    >type_info object as a hash value.


    type_info objects work well in a sorted container, due to their
    "before" member function. But hashing by pointer value should be
    reliable on some platforms at least, just not guaranteed to work by
    the standard, and it probably won't work on Windows.

    Tom
    --
    C++ FAQ: http://www.parashift.com/c -faq-lite/
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    tom_usenet, Jun 1, 2004
    #2
    1. Advertising

  3. tom_usenet wrote:
    >
    > type_info objects work well in a sorted container, due to their
    > "before" member function. But hashing by pointer value should be
    > reliable on some platforms at least, just not guaranteed to work by
    > the standard, and it probably won't work on Windows.
    >
    > Tom


    I'll just use a std::map then, thanks for that.

    --
    http://www.it-is-truth.org/
    Asfand Yar Qazi, Jun 1, 2004
    #3
    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. John Harrison

    Re: RTTI

    John Harrison, Jul 14, 2003, in forum: C++
    Replies:
    2
    Views:
    444
    John Harrison
    Jul 14, 2003
  2. Steven T. Hatton

    <typeinfo>

    Steven T. Hatton, May 10, 2005, in forum: C++
    Replies:
    2
    Views:
    2,917
    Steven T. Hatton
    May 11, 2005
  3. Ganesh
    Replies:
    3
    Views:
    491
    Rolf Magnus
    May 10, 2005
  4. CT
    Replies:
    3
    Views:
    750
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    656
Loading...

Share This Page