Boost logo

Boost Users :

From: Rene Rivera (grafik.list_at_[hidden])
Date: 2006-02-25 13:41:13


pegacorn_at_[hidden] wrote:
> How should I do to replace the constant pointer with shared_ptr?
>
>
> int main()
> {
> const int *ip = new int(1);
> *ip = 2; // NG
> ip = new int(2); // OK
> }
>
> How should I do to achieve the above-mentioned example
> by using shared_ptr?

int main()
{
   boost::shared_ptr<const int> ip(new int(1));
   *ip = 2; // NG
   ip.reset(new int(2)); //OK
}

Is it really hard to understand the documentation such that the answer
isn't obvious? We would really like know so the documentation improves.

--
-- Grafik - Don't Assume Anything
-- Redshift Software, Inc. - http://redshift-software.com
-- rrivera/acm.org - grafik/redshift-software.com
-- 102708583/icq - grafikrobot/aim - grafikrobot/yahoo

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net