This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: typeid strangeness
- To: Stefan Seefeld <seefeld at sympatico dot ca>
- Subject: Re: typeid strangeness
- From: Ross Smith <ross dot s at ihug dot co dot nz>
- Date: Wed, 18 Jul 2001 13:20:03 +1200
- CC: gcc at gcc dot gnu dot org
- Organization: Ihug
- References: <3B54E701.7030307@sympatico.ca>
Stefan Seefeld wrote:
>
> void ServantBase::_add_ref()
> {
> Guard<Mutex> guard(mutex);
> ++_refcount;
> #ifdef LCLOG
> Logger::log(Logger::lifecycle) << "ServantBase::_add_ref on " << this << " ("
> << typeid(this).name() << "): new count is " << _refcount << std::endl;
> #endif
> }
>
> and I'd (of course) like to see which specific subclass / instance gets called.
> However, the type that is being reported is always the base class itself, not
> the actual type. What is wrong ?
Did you forget to make _add_ref() virtual? If it's non-virtual, then the
this pointer will have the static type of the caller (i.e. always
ServantBase) instead of the dynamic type.
--
Ross Smith <ross.s@ihug.co.nz> The Internet Group, Auckland, New Zealand
========================================================================
"Unix has always lurked provocatively in the background of the operating
system wars, like the Russian Army." -- Neal Stephenson