Her. is an example of a progpam that is supposed to use function overloading. Why doesn't it work.
Code:
// display string prblm #1 pg368 c++ primer plus
#include <iostream>
using namespace std;
//prototype (overloading, polymorphism)
void sho_str(const char * str);
void sho_str(const char * str, int n=0);
int main()
{
char dog[10]="Dakota";
sho_str(dog);
sho_str(dog,10);
sho_str(dog,10);
sho_str(dog,10);
return 0;
}
void sho_str(const char * str)
{
cout << str;
}
void sho_str(const char * str, int n)
{
n++;
// number of times function has been executed
static int times=0;
times++;
for (int i=0;i<times;i++)
{
cout << str;
}
}
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
poly.cpp:
Error E2015 poly.cpp 13: Ambiguity between 'sho_str(const char *)' and 'sho_str(
const char *,int)' in function main()
*** 1 errors in Compile ***