Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2002-04-19 12:03:55

On Friday, April 19, 2002, at 09:26 AM, Phil Nash wrote:

> int main()
> {
> shared_handle h(CreateHandle(), &CloseHandle );
> shared_handle h2(h);
> }

It's worth noting that for anything that's a pointer, rather than a
non-pointer type, we have this already. I changed your example to this:


typedef int *HANDLE;

HANDLE CreateHandle()
  return new int(5);

void CloseHandle(HANDLE h)
  std::cout << "CloseHandle(" << *h << ")\n";
  delete h;

typedef boost::shared_ptr<int> shared_handle;

int main()
  shared_handle h(CreateHandle(), &CloseHandle );
  shared_handle h2(h);


Note that the pointer does not have to be created by new and released by
delete as in this example. It can be created by fopen and released by
fclose, or whatever's appropriate.

     -- Darin

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