By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,412 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,412 IT Pros & Developers. It's quick & easy.

RTTI typeinfo pointers

P: n/a
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/
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 22 '05 #2

P: n/a
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/
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.