I am trying to chain together a few overloaded functions. It is something that should be really simple but I am getting errors. Here is the code:
void output(char c[])
{
output(c, 0);
}
void output(char c[], int x)
{
int l = strlen(c) - x;
output(c, x, l);
}
void output(char c[], int x, int y)
{
cout << c;
}
int main()
{
output("myname");
output("myname", 3);
output("myname", 2, 4);
}
The errors I am getting relate the chained parts (output(c, 0); and output(c, x, l);.
The errors are:
"No matching function for call to 'output (char *&, int)'
"No matching function for call to 'output (char *&, int &, int &)'
An explanation of what I have done wrong would be good as well.
I think the problem has to do with the fact that your functions lack prototypes. In cases like that, you should re-order functions so that the ones you call appear ahead of the ones that call them:
But it is best to stick to using prototypes for all functions ahead of defining them.
Also note that string literals are
const. Since your functions do not modify the content of string literals, you should declareconst char c[]instead ofchar c[].