Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-03-22 14:41:46

----- Original Message -----
From: "E. Gladyshev" <egladysh_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, March 22, 2002 1:10 PM
Subject: [boost] plain pointers and shared_ptr

> [...]
> One problem that I'd like to solve is to deal with pointers
> to static objects. I am not sure if there are any smart
> pointer implementations that can reference static objects.
> For example:
> int g_x;
> int main()
> {
> share_ptr<int> tmp(&g_x)
> } //CRASH

Umm...pardon my ignorance, but why do you need a smart
pointer to a static object?

Trying to write generic code that works equally well with
static and dynamic pointers is simply not feasible, as Peter
Dimov pointed out. Just as you cannot write generic code
to eliminate the need to use delete [] vs. delete on raw
pointers, you cannot use generic code to properly destruct
or not destruct a raw pointer. There simply isn't enough
information. Instead, you should provide a version that
handles static pointers, and one that accepts smart pointers,
as Peter again pointed out.


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