jewee
asked on
Question re: functions
If you were to have a case statement in which a function is called for each of the 8 cases, however, a file
case 1:
runProgram(vector1, filename, filename2);
case 2:
runProgram(vector2, filename, filename2);
case 3:
runProgram(vector3, filename, NULL):
However, with case3, a second filename is not needed. Is it sufficient to pass in NULL???? I would rather not create 2 separate functions since it would be rather redundant.
case 1:
runProgram(vector1, filename, filename2);
case 2:
runProgram(vector2, filename, filename2);
case 3:
runProgram(vector3, filename, NULL):
However, with case3, a second filename is not needed. Is it sufficient to pass in NULL???? I would rather not create 2 separate functions since it would be rather redundant.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use the default argument technique of C++. The only problem is you can specify the default arguments only starting from the right hand side.
void runProgram ( some_type vector , string filename1, string filename2 = "" ) ;
case 1:
runProgram(vector1, filename, filename2);
case 2:
runProgram(vector2, filename, filename2);
case 3:
runProgram(vector3, filename):
will solve your purpose.
Cheers!