Suppose I have this code. Your basic \"if the caller doesn\'t provide a value, calculate value\" scenario.
void fun(const char* ptr = NULL)
{
if (ptr==NULL) {
Using overloaded versions of the same function for different input is best, but if you want to use a single function, you could make the parameter be a pointer-to-pointer instead:
void fun(const char** ptr = NULL)
{
if (ptr==NULL) {
// calculate what ptr value should be
}
// now handle ptr normally
}
Then you can call it like this:
fun();
.
char *ptr = ...; // can be NULL
fun(&ptr);