Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

typeid question


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

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

On May 14, 12:31 pm, "michael" <s@begone.net> wrote:

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/

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.
On May 14, 3:29 pm, Ron Natalie <r@spamcop.net> wrote:

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:james.ka@gmail.com
Conseils en informatique oriente objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place Smard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc