As in Java, a function name may be reused with different parameter types.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include <iostream> #include <string> using namespace std; void fred(int a) { cout << "fred the first, " << a << endl; } void fred(int a, string b) { cout << "I am the second fred: " << a << " " << b << endl; } void fred(string c, string d = "ding!") { cout << "Lo, I am fred tertiary. " << c << " " << d << endl; } int main() { fred(17); fred("this"); fred(24, "hours"); fred("some", "day"); } |