This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: typeid strangeness


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]