Re: typeid and dynamic_cast, gcc 3.3
From: Sharad Kala (no.spam_sharadk_ind_at_yahoo.com)
Date: 01/23/04
- Next message: RA Scheltema: "platform independent serialization of a long"
- Previous message: David Rasmussen: "Re: Concurrency"
- In reply to: Andreas Sch.: "Re: typeid and dynamic_cast, gcc 3.3"
- Next in thread: Sharad Kala: "Re: typeid and dynamic_cast, gcc 3.3"
- Reply: Sharad Kala: "Re: typeid and dynamic_cast, gcc 3.3"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 23 Jan 2004 17:00:12 +0530
"Andreas Sch." <no_reply@yahoo.com> wrote in message
news:buqtp6$l9b28$1@ID-152588.news.uni-berlin.de...
> Asfand Yar Qazi wrote:
> >> (...)
> >> void base::printType(base * obj) {
> >> cout << "type is " << typeid(obj).name() << endl;
> >
> > This isn't a virtual function, so it will be called with type of 'this'
> > set to "base", even though it was called from a virtual function
> > (virtual-ness doesn't pass along the calling sequence, its on a
> > per-function basis.) Dynamic-casting
> >
>
> Lets see if I got it: typeid does not evaluate the
> type information in memory but depends on the type
> of the "obj" pointer (and not on what it is pointing to).
This is a quote from msdn -
<Quote>
If the expression points to a base class type, yet the object is actually of a
type derived from that base class, a type_info reference for the derived class
is the result. The expression must point to a polymorphic type (a class with
virtual functions). Otherwise, the result is the type_info for the static class
referred to in the expression. Further, the pointer must be dereferenced so that
the object it points to is used. Without dereferencing the pointer, the result
will be the type_info for the pointer, not what it points to.
</Quote>
Best wishes,
Sharad
Disclaimer : I know msdn isn't totally accurate at places but not here ;-)
- Next message: RA Scheltema: "platform independent serialization of a long"
- Previous message: David Rasmussen: "Re: Concurrency"
- In reply to: Andreas Sch.: "Re: typeid and dynamic_cast, gcc 3.3"
- Next in thread: Sharad Kala: "Re: typeid and dynamic_cast, gcc 3.3"
- Reply: Sharad Kala: "Re: typeid and dynamic_cast, gcc 3.3"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|