10. May 2012 13:00
This is a quick tip in C++ for providing support for optional parameters on functions. This works because when a function is declared in C++ it can be given a default value and when that paramater is missing from the calling function the compiler will automatically add it during compile time and pass the default value.
Heres a simple example of this.
#include <stdio.h>
bool func(bool val = false) {
return val;
}
int main(int argc, char **argv) {
printf("%d\n", func());
printf("%d\n", func(false));
printf("%d\n", func(true));
return 0;
}
4f6282d2-ef6c-428d-ac2f-87e03cab67d2|0|.0