#include "X.h" #include #include #include X::X( int i) : i_( i) {} int X::get_i() { return i_; } struct Y { boost::shared_ptr< X > x_ptr; void init() { x_ptr = boost::shared_ptr< X >( new X( 1) ); } Y() : x_ptr() { boost::once_flag f = BOOST_ONCE_INIT; boost::call_once( f, boost::bind( & Y::init, this) ); } }; X & get_default_X() { static Y y; return * y.x_ptr.get(); }