[prog] C++, global function with optional arguments

Sue Stones suzo at bigpond.net.au
Sat Apr 19 22:25:26 EST 2003


I have written a golbal function with the following declaration
void trim (char str[], int left = 1, int right = 1);

It removes leading and trailing whitespace, if left and right, resectively, 
are true.


When I have the function present without a separate declaration it works Ok, 
but when I remebered that I needed the function deaclaration as well as the 
function itself I got the following errors.


g++     trim.C   -o trim
trim.C: In function `void trim(char*, int, int)':
trim.C:23: default argument given for parameter 2 of `void trim(char*, int = 
1, int = 1)'
trim.C:18: after previous specification in `void trim(char*, int =1, int =1)'
trim.C:23: default argument given for parameter 3 of `void trim(char*, int = 
1, int = 1)'
trim.C:18: after previous specification in `void trim(char*, int =1, int =1)'
make: *** [trim] Error 1
[

Do you know what I am doing wrong?
sue


More information about the Programming mailing list