Posted by
Luigi Ballabio on
Sep 21, 2009; 9:16am
URL: http://quantlib.414.s1.nabble.com/unsafe-upcasting-not-via-pointer-or-reference-in-SwaptionVolatilityMatrix-tp7618p7619.html
On Mon, 2009-09-21 at 15:21 +1000, Yan Kuang wrote:
> Upcasting is safe via pointer or reference, however, I have found in
> swaptionvolmatrix.hpp/ cpp:
>
> In hpp, declared:
>
> Interpolation2D interpolation_;
>
> In cpp:
>
> interpolation_ =
> BilinearInterpolation(swapLengths_.begin(), swapLengths_.end(),
> optionTimes_.begin(), optionTimes_.end(),
> volatilities_);
>
> I think this is not safe.
It's true that during the copy, the object is sliced. However, that is
not a problem. The Interpolation2D object is not polymorphic. What
provides the polymorphic behavior is the contained Impl class, which is
safely stored in a shared_ptr. The result of the copy is an
interpolation object that has lost memory of its original type, but
still works correctly by delegating behavior to its contained Impl.
Luigi
--
If you can't convince them, confuse them.
-- Harry S. Truman
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users