Determining argument is given or omitted by compiler

how to determine / check whether argument is given or omitted in compile time?

1
2
3
4
5
6
bool a_function(char* b, size_t len=0) {
      // no run time check such as if (len ......
      // instead compiler check

      // ...
}
Last edited on
The parameter is not 'omitted' in that sense that the function can determine it. When the function is called without the second parameter the default value is used.

What you can do is using two function with the same name but different paramters.E.g.:
1
2
3
4
5
6
7
8
9
bool a_function(char* b, size_t len) { // Note: no default paramter
      // ...
}

bool a_function(char* b) { // Note: no second parameter

  return a_function(b, strlen(b)); // Calls the function above

}
Topic archived. No new replies allowed.