Boost logo

Boost :

From: Dirk Gregorius (dirk_at_[hidden])
Date: 2004-11-12 06:04:32

My boost::shared_ptr objects hold pointees to interfaces. It might happen
that these raw pointees might become invalid or that I like to change the

Is it possible to change the raw pointee of all boost::shared_ptr objects in
an application due to some kind of event?


I have one singleton class that provides several factory functions:

class Factory
    boost::shared_ptr<IFoo> CreateX( void );
    // ... more factory functions

    // Events -
    void OnChangeImplementationX( void );

    // Data members
    typedef std::vector< boost::shared_ptr<IFoo> > MasterColl;
    MasterColl m_FooObjects;

boost::shared_ptr<X> Factory::CreateX( void )
    // Create a new foo object
    boost::shared_ptr<IFoo> pFoo( new FooImpl );

   // Save a "master" instance
   m_FooObjects.push_back( pFoo );

  // Return the object
  return pFoo;


void Factory::OnChangeImplementationX( void )
    // Iterate over all "master" objects and change the underlying pointee

Can this be implement using the boost::shared_ptr class?



Boost list run by bdawes at, gregod at, cpdaniel at, john at