Posted by
Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/reference-of-boost-shared-ptr-instead-of-Handle-tp7623p7630.html
On Thu, 2009-09-03 at 09:41 +1000, Yan Kuang wrote:
> Luigi Ballabio <
[hidden email]> wrote on 02/09/2009 07:33:35
> PM:
> > Yes, but try this:
> >
> This because constructor of Foo called copy constructor of
> boost::shared_ptr.
That's the same with raw pointers. Look at the following, and forget
about the fact that I'm leaking memory:
#include <iostream>
class T {
int i_;
public:
T(int i) : i_(i) {}
int i() const { return i_; }
};
class Foo {
T* p_;
public:
Foo(T* p) : p_(p) {}
void check() const {
std::cout << p_->i() << std::endl;
}
};
int main() {
T* pA = new T(1);
Foo f(pA);
f.check(); // prints 1
T* pB = new T(2);
pA = pB; // you're changing pA, but not the copy
// stored by the Foo object
f.check(); // in fact, this still prints 1
}
> So Handle behaves like a raw pointer.
Handle behaves like a pointer to pointer. If you're reading appendix A
of my drafts, look at the aside on pointer semantics.
Luigi
--
Never mistake motion for action.
-- Ernest Hemingway
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.
http://p.sf.net/sfu/bobj-july_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users