Login  Register

Re: quantlib Handle compile error

Posted by simoncourtenage on May 24, 2010; 8:20am
URL: http://quantlib.414.s1.nabble.com/quantlib-Handle-compile-error-tp7722p7725.html

On the first point, it is a good idea not to use shared_ptr temporaries in function calls - this page http://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/shared_ptr.htm explain why (see the section on "Best Practices") - the memory leak would only really occur where there are two or more arguments and the evaluation of one arg could potentially lead to an exception being thrown, but it's still a good idea to avoid this coding practice.

Simon Courtenage

On Mon, May 24, 2010 at 8:30 AM, P Nelnik <[hidden email]> wrote:
Thanks Luigi and Simons (I & II) for your responses.

A couple of suggestion:
1: perhaps we should change the code in Examples/EquityOption/EquityOption.cpp:

        Handle<YieldTermStructure> flatTermStructure(
            boost::shared_ptr<YieldTermStructure>(
                new FlatForward(settlementDate, riskFreeRate, dayCounter)));
    since it may leak memory and it sets a bad example.
 
2: When a developer tries to implement Handle<T> where T doesn't derive from Observable,
     he's told there is an error in:
        inline void Handle<T>::Link::linkTo(const boost::shared_ptr<T>& h, bool registerAsObserver) {
    A one line comment in that could warning developers that T must derive from Observable

Cheers
Philip


On Mon, May 24, 2010 at 2:52 PM, Luigi Ballabio <[hidden email]> wrote:
On Mon, 2010-05-24 at 13:35 +0800, P Nelnik wrote:
> When trying to use the quantlib Handle<.>, I got a compiler error:
>
> >c:\work\quantlib\quantlib-1.0.1\ql\handle.hpp(143) : error C2664:
> 'QuantLib::Observer::unregisterWith' : cannot convert parameter 1 from
> 'boost::shared_ptr<T>' to 'const boost::shared_ptr<T> &'

The implementation of Handle<T> requires T to inherit from Observable.

Luigi



--

Glendower: I can call spirits from the vasty deep.
Hotspur: Why, so can I, or so can any man;
But will they come when you do call for them?
-- King Henry the Fourth Part I, Act III, Scene I




------------------------------------------------------------------------------


_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--
------------------------------------------------------------------------
Simon Courtenage                     | simoncourtenage.wordpress.com
Twitter: simoncourtenage         | Skype: simon99ctg
Facebook: Simon Courtenage   | IM: [hidden email]  

------------------------------------------------------------------------------


_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users