Page 1 of 1

typeid operator

Posted: Thu Feb 23, 2006 3:53 am
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?

Re:typeid operator

Posted: Thu Feb 23, 2006 4:01 am
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>...