193030

Template classes

Jul 21st, 2021
985
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data