RE: [Dev-C++] default arguments of a function
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@at...> - 2003-04-16 18:01:42
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Andr? Macario Barros
> Sent: Wednesday, April 16, 2003 8:13 PM
> To: Dev-Cpp-Users
> Subject: [Dev-C++] default arguments of a function
>
>
> Please consider the following code:
>
> #include <blahlib>
> #include <iostream>
> using std::cout;
> using std::endl;
>
> int func(int a=1, int b=2, int c=3);
>
> int main()
> {
> int x=10, y=20, z=30;
>
> blah blah blah code;
>
> cout << func(x,y,z) << endl;
>
> more blah, blah, blah code;
>
> return 0;
> }
>
> int func(int a, int b, int c)
> {
> blah blah blah code;
>
> return(some int);
> }
>
> A) If I call func without arguments, that is, func(), it will
> use the three
> default arguments;
> B) If I use func(x,y), it will consider c value equal to 3;
> C) Idem for func(x), it will consider c=3 and b=2;
> Allways considering the most right side of the arguments list
> as default
> values;
>
> -->My question:
> Is there any way to express func call to say to it to use one or two
> arguments to specific
> parameter, that is, something like func(,y,z) to express that
> I want to pass
> x and y to b and c?
No the above call is not valid. With the default argument mechanism you can
omit arguments from the right of your passed arguments only. If you want to
pass y and z only, you can pass the default value of x.
If the user can't know the any default value, you can change the order of
the argument list or use a variadic function.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
|