By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,245 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,245 IT Pros & Developers. It's quick & easy.

typeid question

P: n/a
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
May 14 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
May 14 '07 #2

P: n/a
On May 14, 12:31 pm, "michael" <s...@begone.netwrote:
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/

May 14 '07 #3

P: n/a
Vallabha wrote:
On May 14, 12:31 pm, "michael" <s...@begone.netwrote:
>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
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.
May 14 '07 #4

P: n/a
On May 14, 3:29 pm, Ron Natalie <r...@spamcop.netwrote:
Vallabha wrote:
On May 14, 12:31 pm, "michael" <s...@begone.netwrote:
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
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.
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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

May 15 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.