Advertisement
193030

Template classes

Jul 21st, 2021
1,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class T>
  6. class Accum
  7. {
  8.     private:
  9.         T total;
  10.     public:
  11.         Accum(T start) : total(start) {};
  12.         T operator+= (T const &t) { return total +=t;}
  13.         T GetTotal() { return total;}
  14.    
  15. };
  16.  
  17. int main()
  18. {
  19.     Accum integers(10);
  20.     integers += 10;
  21.     cout << integers.GetTotal() << endl;
  22.    
  23.     Accum strings(string(""));
  24.     strings += "Vremena";
  25.     strings += " i nravi";
  26.     cout << strings.GetTotal() << endl;
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement