-
-
Save jitpaul/bf7f144a968a801412482db4bf640c89 to your computer and use it in GitHub Desktop.
Templates
This file contains 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; | |
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