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 );

main()
{
   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 @yahoo.com address at http://mail.yahoo.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk