Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Created May 3, 2018
Embed
What would you like to do?
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