Can not Understand the out put of Type Id..

I have written the following code which is producing output like

Fooo bar , Object created

8MyObject
8MyObject
3Box
f
d
c
object 1 and Object 2 are same

Type id does not match

What does these 8 and 3 refers to which precedes MyObject and Box typeids.
Please help me understand this concept.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

class MyObject{

};

class MyObject2{

	public:

		MyObject2()
		{ 
		// cout << "Hii This is going to be the constructor\n\n";
		}

};

class Box:public MyObject{

	public:
		void FurtherTest()
		{
		std::cout <<"\n\n Fooo bar , Object created \n\n";
		}
};

int main()
{
	MyObject m1;
	MyObject m2;
	Box b1;

	b1.FurtherTest();
	float f1;
	double d1;
	char c1;
	std::cout << "\n\n";

	std::cout << typeid(m1).name() << endl;
	std::cout << typeid(m2).name() << endl;

	std::cout << typeid(b1).name() << endl;
	std::cout << typeid(f1).name() << endl;
	std::cout << typeid(d1).name() << endl;
	std::cout << typeid(c1).name() << endl;

if(typeid(m1) == typeid(m2)) std::cout << "\n object 1 and Object 2 are same \n\n";
     else std::cout << "\n\n Objects are not of the xame type\n\n";

if(typeid(f1) != typeid(d1)) std::cout<< "\n\n Type id does not match \n\n";
			else std::cout << "\n\n Type id matchs\n\n";


			return 0;
}
  
Last edited on
Those strings are used internally by the compiler to uniquely identify types. They're not supposed to be understood by external applications. Unless you want to modify or work on GCC, you don't need to understand them.
If you just want to transform them to a human-friendly string, GCC provides a function to do that:
http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
Obviously if you use that function your code will not be portable, since the return value of typeid(x).name() is implementation defined and compilers are not required to provide means to interpret those values.
Topic archived. No new replies allowed.