Re: typeid problem by Larry
Larry
Thu Sep 30 04:32:18 CDT 2004
"david li" <davidli@augmentum.com.cn> wrote in message news:%23Uw7$AspEHA.1816@TK2MSFTNGP09.phx.gbl...
> hi, all:
Greetings.
> I have a piece code like following:
> list<Primitive*> m_primitiveList; //declared in head file
> list<Primitive*>::iterator iter;
>
> I have 2 classes inherited from primitive: Ellipse and Rectangle. then I
> displayed primitive information from this list.
> for(iter = m_primitiveList.begin(); iter != m_primitiveList.end(); iter++)
> {
> cout << "Primitive " << pos++ << ": " << typeid(**iter).name() <<
> endl;
> }
>
> the output of these piece of code as follows:
> Primitive 1: 7Ellipse
> Primitive 2: 9Rectangle
>
> I don't know why there is the number in the front of the class name?
Their are no constraints on the name provided by a typeinfo instance
that would preclude the leading '7' and '9' that you report. If you
expect it to be especially pretty, or even clearly related to the name
of the class, your expectation goes beyond what the C++ standard
requires. I could speculate as to why the implementors decided to
place that leading number in the typeinfo name, but it would not
change the fact that you must provide your own prettified names
if you insist on a particular relation to the class name. One way
to do that would be with a std::map<std::string, std::string>
object, preloaded to map typeinfo::name strings to pretty strings.
You would likely find a macro useful for initializing it.
> thanks so much for answering.
You're welcome.
> win
--
--Larry Brasfield
email: donotspam_larry_brasfield@hotmail.com
Above views may belong only to me.