Posted by
Simon Ibbotson - Straumur on
Feb 28, 2008; 1:49pm
URL: http://quantlib.414.s1.nabble.com/Handle-type-casting-tp11733p11737.html
If the new object is of type T3 (not inherited from type T2, but is
inherited from type T1), then the dynamic cast to type T2 fails and the
pointer is set to NULL.
The accessor functions in Handle already check for this scenario (NULL
pointer) and throw exceptions in this case: so unless a function tries
to use the dereferenced NULL pointer, there is no problem. It would be
as if the typecast occurred at the time the Handle<T2> was dereferenced
and would be "as if" the original Handle<T1> was passed, dereferenced
and typecast.
Simon
-----Original Message-----
From: Luigi Ballabio [mailto:
[hidden email]]
Sent: 28 February 2008 13:31
To: Simon Ibbotson
Cc:
[hidden email]
Subject: RE: [Quantlib-dev] Handle & type casting
On Thu, 2008-02-28 at 13:06 +0000, Simon Ibbotson wrote:
> If you have a handle to any Observable - Handle<T1> but you need a
> handle to a derived type Handle<T2>, I can find no way of currently
> doing this without going through the process of
> a) Getting the underlying boost::shared_ptr<T1>
> b) Using boost::dynamic_pointer_cast to get a boost::shared_ptr<T2>
> c) Creating a Handle<T2> using the new shared_ptr<T2>.
>
> Unfortunately, this means that if the original Handle<T1> points to a
> new object, the Handle<T2> does not point to this updated object.
Ok. Let's say you keep the Handle<T2> connected to the original Handle.
What happens if the new object is not a T2?
Luigi
--
Better to have an approximate answer to the right question than a
precise answer to the wrong question.
-- John Tukey as quoted by John Chambers
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev