typeid question

M

michael

Hi All,

I have the following:

class ClassA {
};

class ClassB {
};

int main(){
ClassA a;
ClassB b;

cout << typeid(a).name() << endl;
cout << typeid(b).name() << endl;
}

when this executes it prints:

6ClassA
6ClassB

Where does the '6' come from?

Thanks for your help

Regards Michael
 
M

Michael DOUBEZ

michael a écrit :
[snip]
cout << typeid(a).name() << endl;
cout << typeid(b).name() << endl;

when this executes it prints:

6ClassA
6ClassB

Where does the '6' come from?

It is the length of the string I guess.

Note: The output of typeid().name() is implementation defined.

Michael
 
V

Vallabha

Hi All,

I have the following:

class ClassA {

};

class ClassB {

};

int main(){
ClassA a;
ClassB b;

cout << typeid(a).name() << endl;
cout << typeid(b).name() << endl;

}

when this executes it prints:

6ClassA
6ClassB

Where does the '6' come from?

Thanks for your help

Regards Michael

I compiled your code on my Solaris box and it gave me correct results.

../a.out
classA
classB

I used Sun Studio11 C++ compiler.

Cheers
-Vallabha
S7 Software Solutions
http://www.s7solutions.com/
 
R

Ron Natalie

Vallabha said:
I compiled your code on my Solaris box and it gave me correct results.

./a.out
classA
classB
The results are correct on both machines. The return of typeid is
implementation specific. There's no guarantee that it's meaningful
to humans at all. It's certainly NOT unique (nor required to be) for
distinct types.
 
J

James Kanze

The results are correct on both machines. The return of typeid is
implementation specific. There's no guarantee that it's meaningful
to humans at all. It's certainly NOT unique (nor required to be) for
distinct types.

In fact, an empty string for every type would also be
conforming. It's also not required to be the same for the same
type; outputting the address of the typeid object would also be
conform. (On the other hand, it's implementation defined, so
the implementation is required to document what it does.)

Some implementations choose to do something useful. Others not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,212
Latest member
SteveMagga

Latest Threads

Top