[C++] Knowing when non-const base member functions are called

From: Pocaterra (olivertwist_at_dickens.co.uk)
Date: 10/22/04


Date: Fri, 22 Oct 2004 15:57:59 -0600

Hi:

Suppose I have something like the following:

class Derived : public Base
{
   mutable std::auto_ptr<SomeType> m_cachedValue;

   virtual void createCachedValue() { ... }
   virtual const SomeType& cachedValue() const
   {
      if( !m_cachedValue.get()
        createCachedValue();

       return *m_cachedValue;
   }
};

I would like to be able to determine when non-const member functions of
Base are called, so that I can delete the cached value that depends on
the data in Base. Is there anyway I can do this?

I've tried making Derived have private inheritance from Base, and then
having 'Base&' and 'const Base&' cast operators, but this doesn't work.

Thanks,
Cameron


Quantcast