typeid operator

Programming, for all ages and all languages.
Post Reply
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

typeid operator

Post by Neo »

The output of the following program

Code: Select all

#include<iostream.h>
class yourclass { };
int main()
{
        int i;         
        float j;
        char c;
        double db;
        yourclass a;
        cout << " i is " << typeid(i).name() << endl;
        cout << " j is " << typeid(j).name() << endl;
        cout << " db is " << typeid(db).name() << endl;
        cout << " c is " << typeid(c).name() << endl;
        cout << " a is " << typeid(a).name() << endl;
        return 0;
}
is
i is i
j is f
db is d
c is c
a is 9yourclass
Now how come the name of the user defined type (myclass) is printed (in full) whereas the standard datatypes are just one char?
What is the reason behind this?
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:typeid operator

Post by Solar »

It's "implementation defined", i.e. you should ask the compiler builders that question. I'd guess efficiency (both in storage space and comparison times).

BTW, VisualStudio 6 delivers:
i is int
j is float
db is double
c is char
a is class yourclass
Oh, and iostream.h is deprecated. Use <iostream>...
Every good solution is obvious once you've found it.
Post Reply