RTTI typeinfo pointers

  • Thread starter Asfand Yar Qazi
  • Start date
A

Asfand Yar Qazi

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
 
T

tom_usenet

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
 
A

Asfand Yar Qazi

tom_usenet said:
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.
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top