Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Created May 3, 2018 19:38
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 jitpaul/bf7f144a968a801412482db4bf640c89 to your computer and use it in GitHub Desktop.
Save jitpaul/bf7f144a968a801412482db4bf640c89 to your computer and use it in GitHub Desktop.
Templates
#include <iostream>
using namespace std;
template <int val = 3, class T = int>
struct Example {
int multiplier = val;
T func(T a) {
a *= multiplier;
return a;
}
};
int main() {
Example <> e1;
Example <5> e2;
Example <2, float> e3;
cout << e1.func(1) << endl;
cout << e2.func(4) << endl;
cout << e3.func(2.4) << endl;
cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment