Vitual Construction

This forum is to discuss the book "C++ design patterns and derivatives pricing."

Vitual Construction

Postby Xman » Tue Jul 31, 2012 5:36 am

In the following code (p 44, 2nd edition)

Payoff* PayOffCall::clone() const
return new PayOffCall(*this);

My understanding is that you return a pointer of PayOffCall using the content of *this. But when I check PayOff3.h, there is no constructor defined in the format of PayOffCall::PayOffCall(PayOffCall & callPayOff).
Are you calling the default copy constructor? If yes, is this always how this should be done, meaning calling the default copy constructor instead of define your own?
Posts: 4
Joined: Tue Jun 26, 2012 5:04 pm

Re: Vitual Construction

Postby mj » Tue Jul 31, 2012 9:22 am

it is calling the default copy constructor

you should only define a copy constructor if the default one is not adequate.

As I discuss much later in the book (2nd ed) these days I almost never define a copy
Site Admin
Posts: 1380
Joined: Fri Jul 27, 2007 7:21 am

Return to C++ design patterns and derivatives pricing

Who is online

Users browsing this forum: No registered users and 1 guest