fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename Type, int FixedTemplatedValue>
  5. void TemplatedFunc(Type value)
  6. {
  7. std::cout << "Fixed templated value: " << FixedTemplatedValue
  8. << "\tPassed in changable value: " << value << std::endl;
  9. }
  10.  
  11. int main()
  12. {
  13. auto FuncSeventeen = &TemplatedFunc<std::string, 17>;
  14. auto FuncTwoHundred = &TemplatedFunc<float, 200>;
  15.  
  16. //NOTE: These functions always print "17" as their fixed value,
  17. //because it's now BUILT INTO the function.
  18. //They also always take a std::string as their first parameter, because it's BUILT IN at compile time,
  19. //but they let you decide at run time what the value of that string is.
  20. FuncSeventeen("Meow");
  21. FuncSeventeen("Purr");
  22.  
  23. //NOTE: These functions always print "200" as their fixed value,
  24. //because it's now BUILT INTO the function.
  25. //They also always take a float as their first parameter, because it's BUILT IN at compile time,
  26. //but they let you decide at run time what the value of that float is.
  27. FuncTwoHundred(0.257f);
  28. FuncTwoHundred(1.5f);
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
Fixed templated value: 17	Passed in changable value: Meow
Fixed templated value: 17	Passed in changable value: Purr
Fixed templated value: 200	Passed in changable value: 0.257
Fixed templated value: 200	Passed in changable value: 1.5