Skip to main content
gamedev.net
🔒 Locked

Suspicious parameter.

Started by KurtCPP 2 replies 400+ views
Original Post
KurtCPP
KurtCPP
Hi''ve seen in a book a statement looking like the following. Couls someone shed light on this, please? Function(double = 0); I cant remember whether it was declaration but I still think it was. What does double = 0 do here?? Thanks to all in advance. Prog, Hex & Rock''n''Roll : I don''t like the Prog but the Prog likes me. Some nice poetry to sweeten your spirit and relax a bit before programming
Prog, Games & Rock'n'Roll :I don't like the Prog but the Prog likes me.
Blutdurst
Blutdurst
Hi!

The double=0 puts 0 per default to the first paraemter of the function.
So, for the function call, it is optional to specify the parameter. If none is specified, the value is 0, otherwise, it''sthe value given

regards
Blutdurst
KurtCPP
KurtCPP
OK but what if I still wanna specify a parameter name?? Shall I simply write double fValue = 0?? I suppose it gotta be this since a parameter w/o name would be kinda useless according to me...

Prog, Hex & Rock''n''Roll :
I don''t like the Prog but the Prog likes me.
Some nice poetry to sweeten your spirit and relax a bit before programming
Prog, Games & Rock'n'Roll :I don't like the Prog but the Prog likes me.
GroZZleR
GroZZleR
As far as I can tell, you''re just getting hung up on the concept that its not specifiying a name in the prototype, where as in the definition, you would have to.

Example:
Function(int, int, int);

Is perfectly fine, and would be defined like:
Function(int x, int y, int z)
{
return x + y + z;
}

So yes, if you want to specifiy a name in the prototype, go right ahead.

Function(double MyDouble = 0);

Is just fine.

I personally prefer the latter, to put names with my prototypes.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.