Skip to content

Instantly share code, notes, and snippets.

@jameskyle
Created August 16, 2019 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameskyle/53861903f2ef5ff5bd5bfe0fb5b2be35 to your computer and use it in GitHub Desktop.
Save jameskyle/53861903f2ef5ff5bd5bfe0fb5b2be35 to your computer and use it in GitHub Desktop.
foo.cpp
#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