I need to have a default value for a string in a function parameter, but the function call keeps complaining "no matching function for call..." when called with no parameters. I'm trying to do this with different ways:
Default values are a feature of the prototype, not the implementation. They are merely 'syntactic sugar' that the compiler uses to provide parameters at compile time that the programmer omitted to specify. They are not part of the function definition itself.
But I have another template class where I used default values in the implementation and not in the prototypes!!! that's why I'm surprised. (Since it's a template class, it has everything in a single file, not in 2 files like in this case. Does this have anything to do with that?)
But I have another template class where I used default values in the implementation and not in the prototypes!!!
a templated class/function is actually a prototype which you instantiate later.
having a default parameter in the implementation doesn't make any sense since it's totally veilled from the user of that function. If you had something like that
1 2 3 4 5 6 7
void func(int i, int j); // prototype
...
void func(int i, int j = 0) // the user of func() must provide 'j', what's the default parameter good for?
{
}