|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-10-02 07:07:00
From: "David B. Held" <dheld_at_[hidden]>
> It seems to me that smart pointers present a bit of a problem when it
> comes time to pass them as arguments to a function. Consider a
> case with raw pointers:
>
> class foo
> {
> public:
> int bar() const { return bar_; }
> void baz(int n) { bar_ = n; }
> private:
> int bar_;
> };
>
> void g(foo const* p)
> {
> p->bar();
> p->baz(3); // Error!
> }
>
> We can, of course, call foo::bar(), because it is a const function. We
> cannot call foo::baz(), because it is not const. Now, consider the case
> with, say, shared_ptr<>:
>
> typedef shared_ptr<foo> foo_ptr;
typedef foo * foo_ptr;
> void g(foo_ptr const& p)
> {
> p->bar();
> p->baz(3); // No Error!
Ditto.
> }
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk