Created
August 16, 2019 20:44
-
-
Save jameskyle/53861903f2ef5ff5bd5bfe0fb5b2be35 to your computer and use it in GitHub Desktop.
foo.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void overloaded(int a) { | |
cout << "This is an int: " << a << endl; | |
} | |
void overloaded(double a) { | |
cout << "This is a double: " << a << endl; | |
} | |
void overloaded(string a) { | |
cout << "This is a string: " << a << endl; | |
} | |
template <class T> | |
void dispatch(T a) { | |
overloaded(a); | |
} | |
int main() { | |
int a = 5; | |
double b = 15.0; | |
string c = "hello, world"; | |
dispatch(a); | |
dispatch(b); | |
dispatch(c); | |
} | |
/** | |
Output: | |
This is an int: 5 | |
This is a double: 15 | |
This is a string: hello, world | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment