Ch.2 pg 15 Listing 2.2

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

Ch.2 pg 15 Listing 2.2

Postby chesswizard » Fri May 13, 2011 8:36 am

What does the following code do?

PayOff::PayOff(double Strike_, OptionType TheOptionsType_)
:
{
}

I know the :: is a scope operator but I'm confused by the : operator and why they empty code between the { }? I think it is related to the header file in some way. Thanks.

Great book by the way!
chesswizard
 
Posts: 2
Joined: Fri May 13, 2011 8:23 am

Re: Ch.2 pg 15 Listing 2.2

Postby mj » Mon May 16, 2011 12:05 am

It's the stuff between the : and the { which is missing from your post that does something -- it says how to initialize the class data members.

We need the { } to make it clear that the function is a definition and does nothing else.
mj
Site Admin
 
Posts: 1380
Joined: Fri Jul 27, 2007 7:21 am

Re: Ch.2 pg 15 Listing 2.2

Postby chesswizard » Tue May 17, 2011 8:19 am

Great, thanks
chesswizard
 
Posts: 2
Joined: Fri May 13, 2011 8:23 am

Re: Ch.2 pg 15 Listing 2.2

Postby jash » Tue May 15, 2012 12:16 pm

Also on the same page what is the point of:
Code: Select all
(double spot)
in the following line
Code: Select all
double PayOff::operator ()(double spot) const


I have never seen two sets of parenthesis next to each other like that
jash
 
Posts: 1
Joined: Tue May 15, 2012 12:05 pm

Re: Ch.2 pg 15 Listing 2.2

Postby mj » Tue May 15, 2012 9:19 pm

this means you are defining the operator with no name that just takes an argument. So you can
write

PayOff object(...);

object(x);

the second line is equivalent to

object.operator()(x);
mj
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

cron