Please help me in this... | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 4

Please help me in this...

https://code.sololearn.com/c699yKj5ysmA/?ref=app Why are there numbers along with the words?

6th May 2017, 2:59 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
6 Réponses
+ 5
That is the way the compiler shows the typeid of variables. Each compiler will print different results. I Think the P means a pointer. Try diferent types to find out the way the compiler describes types.
6th May 2017, 3:30 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 5
As Ulisses hinted at, this is the result of "name mangling". It's used to differentiate between constructs of the same name during the compilation and linking process (consider function overloading, or having two constructs in different namespaces with the same names). How this happens is implementation-defined. In this case, "P" indicates a pointer, and the number is simply the number of characters in the class name. That's just how GCC chooses to do things. With MSVC, you get the following outputs: class Base * class Base * class Base class Derived
6th May 2017, 9:28 PM
Squidy
Squidy - avatar
+ 4
I was searching on that and it looks like there is a way (a function) that prints more meaningfull information. I did not read everything but maybe you will undertsand how to do that in this article: https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
6th May 2017, 3:46 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 3
Why is there 4,7 in the output as well?
6th May 2017, 3:31 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 3
@Ulisses Crus & @Squidy Thank You! Wow, GCC even counts the letters in the class name... But what use can that be?
7th May 2017, 3:39 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 3
Similarly: On printing this: long a; cout<<typeid(a).name<<endl; I get: l //Just an l?
7th May 2017, 3:42 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar