-
April 1st, 2009, 10:27 PM
#1
Default function parameter
Hi All,
I have some question with default function parameter, The question is when I declare function pnd set parameter like
void Func(int a, int b=1)
{
}
void main()
{
//If I call
Func(10);
//The call
Func(10,11)
}
In this case, what is function signature of "Func"?
thank
-
April 1st, 2009, 10:59 PM
#2
Re: Default function parameter
In the first call, 'a' will be 10 and 'b' will be the default 1.
In the second call, 'a' will be 10 and 'b' will be 11
Intel Core Duo Macbook w/ Mac OS 10.5.6
gcc 4.2.1 (i386-apple-darwin9.1.0) and Xcode 3.1.1
-
April 1st, 2009, 11:06 PM
#3
Re: Default function parameter
Hi Etherous,
Thank you very much for your reply
How the compiler generate function signature format?
Thank
-
April 2nd, 2009, 03:32 AM
#4
Re: Default function parameter
void (*Func)(int, int = 1)
-
April 2nd, 2009, 10:54 AM
#5
Re: Default function parameter
The function signature does not include the default values for the parameter. It is only a guide for the compiler to put some value if the parameter is not specified. Your function signature would be
Code:
void Func(int a, int b)
The default parameter is visible only to the scope where you declared it. If you declared it in the header file, it can be seen by other modules using the header file. If you declared it in the CPP file, only those codes within that CPP can see the default values. You can even change the parameter defaults in other modules. For example you have another module named b.cpp. You can use the function as
Code:
extern void Func(int a = 10, int b = 0);
...
Func(); // call it with 2 default parameters
Hope it will clarify your concers
-
April 3rd, 2009, 03:45 AM
#6
Re: Default function parameter
Hi rxbagain
Thank you very much, This reply is very useful.
thank!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|