Hi, Since class ZeroSpreadedTermStructure is derived from YieldTermStructure, it should have methods like discount(). I have a simple example, when compiling it screams, error: request for member ‘discount’ in ‘discTerm’, which is of non-class type ‘QuantLib::ZeroSpreadedTermStructure(QuantLib::Handle<QuantLib::YieldTermStructure>, QuantLib::Handle<QuantLib::Quote>)’ // code snippet: std::vector<Date> dates(4); dates[0] = Date(1,Jan,2014); dates[1] = Date(1,Feb,2014); dates[2] = Date(1,Jun,2014); dates[3] = Date(1,Dec,2014); std::vector<Rate> yields(4); yields[0] = 0.1; yields[1] = 0.2; yields[2] = 0.3; yields[3] = 0.4; DayCounter dayCounter = Actual360(); boost::shared_ptr<Quote> spread(new SimpleQuote(0.01)); boost::shared_ptr<YieldTermStructure> ftpTerm(new InterpolatedZeroCurve<ForwardFlat> (dates,yields,dayCounter,Calendar(),ForwardFlat())); ZeroSpreadedTermStructure discTerm(Handle<YieldTermStructure>(ftpTerm), Handle<Quote>(spread)); std::cout<<discTerm.discount(1.0, true)<<std::endl; --------------- what's the problem? Regards! ------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
cheng, thanks for your response. Indeed, the problem comes from the constructor calling. The key point is the ZeroSpreadTermStructure's constructor has template arguments(Handle<>), so the compiler may have trouble when parsing this constructor. After posting this question, I've fixed it by changing: ZeroSpreadedTermStructure discTerm(Handle<YieldTermStructure>(ftpTerm), Handle<Quote>(spread)) with: ZeroSpreadedTermStructure discTerm = ZeroSpreadedTermStructure(Handle<YieldTermStructure>(ftpTerm), Handle<Quote>(spread)); Your solutions work well. Could you elaborate on the c++ trick you mentioned? Why did you bracket the first parameter of the constructor function? ------------------ 原始邮件 ------------------ 发件人: "cheng li";<[hidden email]>; 发送时间: 2014年12月25日(星期四) 下午2:00 主题: 答复: [Quantlib-users] question about 'ZeroSpreadedTermStructure' Hi Rage, This is a c++ trick. The following line: ZeroSpreadedTermStructure discTerm(Handle<YieldTermStructure>(ftpTerm), Handle<Quote>(spread)); Actually declare a function named discTerm and with parameters as Handle<YieldTermStructure> and Handle<Quote>, while return type as ZeroSpreadedTermStructure; To avoid compiler to do such silly thing, you can change the line as follows: ZeroSpreadedTermStructure discTerm((Handle<YieldTermStructure>(ftpTerm)), Handle<Quote>(spread)); Or Handle<YieldTermStructure> curveHandle(ftpTerm); Handle<Quote> quoteHandle(spread); ZeroSpreadedTermStructure discTerm(curveHandle, quoteHandle); Regards, Cheng 发件人: rage [mailto:[hidden email]] Hi, Since class ZeroSpreadedTermStructure is derived from YieldTermStructure, it should have methods like discount(). I have a simple example, when compiling it screams, error: request for member ‘discount’ in ‘discTerm’, which is of non-class type ‘QuantLib::ZeroSpreadedTermStructure(QuantLib::Handle<QuantLib::YieldTermStructure>, QuantLib::Handle<QuantLib::Quote>)’ // code snippet: std::vector<Date> dates(4); dates[0] = Date(1,Jan,2014); dates[1] = Date(1,Feb,2014); dates[2] = Date(1,Jun,2014); dates[3] = Date(1,Dec,2014); std::vector<Rate> yields(4); yields[0] = 0.1; yields[1] = 0.2; yields[2] = 0.3; yields[3] = 0.4; DayCounter dayCounter = Actual360(); boost::shared_ptr<Quote> spread(new SimpleQuote(0.01)); boost::shared_ptr<YieldTermStructure> ftpTerm(new InterpolatedZeroCurve<ForwardFlat> (dates,yields,dayCounter,Calendar(),ForwardFlat())); ZeroSpreadedTermStructure discTerm(Handle<YieldTermStructure>(ftpTerm), Handle<Quote>(spread)); std::cout<<discTerm.discount(1.0, true)<<std::endl; --------------- what's the problem? Regards! ------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
This is known in C++ circles as "the most vexing parse". Wikipedia has an article on it: http://en.wikipedia.org/wiki/Most_vexing_parse It always comes as a surprise but as Cheng points out an extra pair of parentheses resolves the ambiguity for the compiler. Best regards Alexander On Dec 27, 2014 3:50 AM, "rage" <[hidden email]> wrote:
------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by rage-3
hrere is some background. clang, always very nice and communicative,
throws a warning and a suggestion how to solve this. http://en.wikipedia.org/wiki/Most_vexing_parse regards Peter On 27 December 2014 at 03:25, rage <[hidden email]> wrote: > cheng, thanks for your response. > > Indeed, the problem comes from the constructor calling. The key point is the > ZeroSpreadTermStructure's constructor has template arguments(Handle<>), so > the compiler may have trouble when parsing this constructor. > > After posting this question, I've fixed it by changing: > ZeroSpreadedTermStructure discTerm(Handle<YieldTermStructure>(ftpTerm), > Handle<Quote>(spread)) > with: > ZeroSpreadedTermStructure discTerm = > ZeroSpreadedTermStructure(Handle<YieldTermStructure>(ftpTerm), > Handle<Quote>(spread)); > > Your solutions work well. Could you elaborate on the c++ trick you > mentioned? Why did you bracket the first parameter of the constructor > function? > > > ------------------ 原始邮件 ------------------ > 发件人: "cheng li";<[hidden email]>; > 发送时间: 2014年12月25日(星期四) 下午2:00 > 收件人: "rage"<[hidden email]>; > "'quantlib-users'"<[hidden email]>; > 主题: 答复: [Quantlib-users] question about 'ZeroSpreadedTermStructure' > > Hi Rage, > > > > This is a c++ trick. The following line: > > > > ZeroSpreadedTermStructure discTerm(Handle<YieldTermStructure>(ftpTerm), > Handle<Quote>(spread)); > > > > Actually declare a function named discTerm and with parameters as > Handle<YieldTermStructure> and Handle<Quote>, while return type as > ZeroSpreadedTermStructure; > > > > To avoid compiler to do such silly thing, you can change the line as > follows: > > > > ZeroSpreadedTermStructure discTerm((Handle<YieldTermStructure>(ftpTerm)), > Handle<Quote>(spread)); > > > > Or > > > > Handle<YieldTermStructure> curveHandle(ftpTerm); > > Handle<Quote> quoteHandle(spread); > > ZeroSpreadedTermStructure discTerm(curveHandle, quoteHandle); > > > > Regards, > > Cheng > > > > 发件人: rage [mailto:[hidden email]] > 发送时间: 2014年12月25日 0:10 > 收件人: quantlib-users > 主题: [Quantlib-users] question about 'ZeroSpreadedTermStructure' > > > > Hi, > > Since class ZeroSpreadedTermStructure is derived from YieldTermStructure, it > should have methods like discount(). I have a simple example, when compiling > it screams, > > error: request for member ‘discount’ in ‘discTerm’, which is of non-class > type > ‘QuantLib::ZeroSpreadedTermStructure(QuantLib::Handle<QuantLib::YieldTermStructure>, > QuantLib::Handle<QuantLib::Quote>)’ > > > > > > > > // code snippet: > > std::vector<Date> dates(4); > > dates[0] = Date(1,Jan,2014); > > dates[1] = Date(1,Feb,2014); > > dates[2] = Date(1,Jun,2014); > > dates[3] = Date(1,Dec,2014); > > > > std::vector<Rate> yields(4); > > yields[0] = 0.1; > > yields[1] = 0.2; > > yields[2] = 0.3; > > yields[3] = 0.4; > > > > DayCounter dayCounter = Actual360(); > > boost::shared_ptr<Quote> spread(new SimpleQuote(0.01)); > > boost::shared_ptr<YieldTermStructure> ftpTerm(new > InterpolatedZeroCurve<ForwardFlat> > > (dates,yields,dayCounter,Calendar(),ForwardFlat())); > > > > ZeroSpreadedTermStructure discTerm(Handle<YieldTermStructure>(ftpTerm), > Handle<Quote>(spread)); > > > > std::cout<<discTerm.discount(1.0, true)<<std::endl; > > > > --------------- > > what's the problem? > > > > Regards! > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming! The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users > ------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by rage-3
The compiler doesn't have any problem parsing the statement, template arguments or not. The problem is that, according to the standard, your original statement is not a constructor call but a function declaration. Google "most vexing parse" for a full explanation. Luigi On Dec 27, 2014 3:45 AM, "rage" <[hidden email]> wrote:
------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |