Assigning function pointers to overloaded functions
#include <iostream>
using namespace std;
void space(int count)
{
for( ; count; count--)
cout << ' ';
}
void space(int count, char ch)
{
for( ; count; count--)
cout << ch;
}
int main()
{
void (*functionPointer1)(int);
void (*functionPointer2)(int, char);
functionPointer1 = space; // gets address of space(int)
functionPointer2 = space; // gets address of space(int, char)
functionPointer1(22);
cout << "|\n";
functionPointer2(30, 'x');
cout << "|\n";
return 0;
}
Related examples in the same category