Vita94

NVitanovic C++ Tutorial 23 - Template example

May 27th, 2018
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. class cSum
  6. {
  7.     T value;
  8. public:
  9.     cSum(T first, T second)
  10.     {
  11.         value = first + second;
  12.     }
  13.     T Result() { return value; }
  14. };
  15. int main()
  16. {
  17.     cSum<int> sum1(1, 4);
  18.     cout << sum1.Result() << endl;
  19.     cSum<float> sum2(1.2, 5.2);
  20.     cout << sum2.Result() << endl;
  21.     getchar();
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment