Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2002-03-21 00:25:25

A smart pointer question,
will this code crash?


void foo( int* p );

   int x;

   foo( &x );

   return 0;

void foo( int *x )
   //foo() has no idea how 'x' has been allocated
   //but shared_ptr<> is smarter then foo() is.
   //It is a smart pointer after all.
   shared_ptr<int> xp( x );

   //... call some other functions with x or xp ...
   //shared_ptr<> should make sure that the
   //object is not deleted while foo() is using it.

   *xp = 0;

Do You Yahoo!?
Get your free address at

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