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

curious about typeid().name()

P: n/a
In reading "Thinking about C++ V2" I started using the TestSuite
described in Ch2. In it there are lines that print out
typeid(*this).name(). In the book it shows up as "TestXXX" but in
actual experience with G++ it prints out "##TestXXX" instead. For
instance, WinHelpersTest gets printed as "14WinHelpersTest".

Is G++ behaving appropriately? No other examples on web of
type_info::name show a return like that; they all show "ClassName"
instead of "##ClassName".

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Noah Roberts wrote:
In reading "Thinking about C++ V2" I started using the TestSuite
described in Ch2. In it there are lines that print out
typeid(*this).name(). In the book it shows up as "TestXXX" but in
actual experience with G++ it prints out "##TestXXX" instead. For
instance, WinHelpersTest gets printed as "14WinHelpersTest".

Is G++ behaving appropriately? No other examples on web of
type_info::name show a return like that; they all show "ClassName"
instead of "##ClassName".


The Standard does not specify how the name should appear. In fact, it
doesn't require anything meaningful at all. It's implementation-defined,
and for all C++ cares, your compiler may just output an empty string for
every type there is.

V
Jul 23 '05 #2

P: n/a
Noah Roberts wrote:
In reading "Thinking about C++ V2" I started using the TestSuite
described in Ch2. In it there are lines that print out
typeid(*this).name(). In the book it shows up as "TestXXX" but in
actual experience with G++ it prints out "##TestXXX" instead. For
instance, WinHelpersTest gets printed as "14WinHelpersTest".

Is G++ behaving appropriately? No other examples on web of
type_info::name show a return like that; they all show "ClassName"
instead of "##ClassName".


The specific form of the return value of 'type_info::name()' is
implementation defined. Strictly speaking, the implementation is not
even required to return anything "meaningful" from 'type_info::name()'.
Formally, it can return a pointer to "Hello World!" string every time
you call it, for all instances of 'type_info'.

Normally, the compiler would return a more or less mangled string, which
at least remotely resembles the actual name of the type. What you
observe in your case is perfectly fine, nothing unusual.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.