Topic: Q: why default params from the end only?
Author: robert@alkymi.unit.no (Robert Schmidt)
Date: Thu, 25 Feb 93 15:58:14 GMT Raw View
Why is it that C++ accepts default parqameters starting from the end of
the parameter list only?
Consider:
void print(char*s, int x=0, int y=0, int color=-1)
This function should use the current cursor coordinates if x or y is
unsecified, and some default color if color is unspecified.
Now, I can call
print("testing",4);
to print starting from column 4 at the current line in the default
color, or even
print("testing");
to continue from current position in current color.
However, I think C++ should also allow this case:
print("testing",,,2);
where x and y are unspecified and color == 2. Is this possible to
add into the C++ standard, or will empty parameters in the middle of
the list mess up things?
In any case, what is the most elegant way of working around this,
so that the user doesn't have to know what the default values are?
--
Robert Schmidt - robert@alkymi.unit.no - Buuud@IRC
Ztiff Zox Softwear: fast/tiny utilities, games/graphics programming on
the DOS platform (C/C++ & asm). Suggestions welcome!
This is a .sig coke can! Pour me into your .sig, and join in!
Author: pjl@cs.uiuc.edu (Paul Lucas)
Date: Thu, 25 Feb 1993 18:12:14 GMT Raw View
In <1993Feb25.155814.1094@ugle.unit.no> robert@alkymi.unit.no (Robert Schmidt) writes:
>Why is it that C++ accepts default parqameters starting from the end of
>the parameter list only?
[example elided]
>Is this possible to
>add into the C++ standard, or will empty parameters in the middle of
>the list mess up things?
ARM, p. 142, very top.
>In any case, what is the most elegant way of working around this,
>so that the user doesn't have to know what the default values are?
The default should be the most natural or most-often used
value. If you find users having to know what the default is,
perhaps it ought not to be default.
--
- Paul J. Lucas
AT&T Bell Laboratories
Naperville, IL
Author: hagiwara@zuken.co.jp (Kazuyuki Hagiwara)
Date: 26 Feb 93 07:04:57 GMT Raw View
In article <1993Feb25.155814.1094@ugle.unit.no> robert@alkymi.unit.no (Robert Schmidt) writes:
>>Why is it that C++ accepts default parqameters starting from the end of
>>the parameter list only?
>>Consider:
>>void print(char*s, int x=0, int y=0, int color=-1)
>>However, I think C++ should also allow this case:
>>print("testing",,,2);
You should have a screen or cursor object. (... this is the c++ news group)
How about:
screen.move_cursor(10,20);
screen.print("testing",2);
You can call several messages if you declare member functions returning
reference of object:
class Screen {
public:
Screen& move_corsor(int,int);
Screen& print(char* s,int color=-1);
...
};
screen.move_cursor(10,20).print("testing");
--
Kazuyuki Hagiwara @ Zuken, Inc. Yokohama, Japan (hagiwara@zuken.co.jp)