Advertisement
alvsjo

template header

Dec 29th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #ifndef ARRAYTEMPLATE_H
  2. #define ARRAYTEMPLATE_H
  3.  
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8.  
  9. template <class T>
  10. class ArrayTemplate;
  11. template <class T>
  12. ostream& operator<< (ostream& os, ArrayTemplate<T>& a);
  13.  
  14. template <class T>
  15. class ArrayTemplate
  16. {
  17. private:
  18.     T* data;
  19.     int cap;
  20.     int br;
  21.  
  22.     public:
  23.  
  24.         ArrayTemplate(int c);
  25.         ArrayTemplate(const ArrayTemplate<T>& a);
  26.         virtual ~ArrayTemplate();
  27.  
  28.         ArrayTemplate<T>& operator=(const ArrayTemplate<T>& a);
  29.         T& operator[](int index);
  30.         bool operator==(const ArrayTemplate<T>& a);
  31.         int getCap() const{return this->cap;}
  32.         int getBr()const {return this->br;}
  33.        template <class J>
  34.         friend ostream& operator<< (ostream& os, ArrayTemplate<J>& a)
  35.  
  36. {
  37.  
  38.     os<< "Broj Elemenata: "<<a.getBr()<< " Kapacitet: " << a.getCap()<<endl;
  39.      for(int i=0; i < a.getBr(); i++)
  40.     {
  41.         os <<a[i]<< " ";
  42.     }
  43.    // os << endl;
  44.     return os;
  45. }
  46.  
  47.  
  48.  
  49.         void Dodaj(T newElem);
  50.  
  51. };
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. #include "ArrayTemplate.cpp"
  61.  
  62. #endif // ARRAYTEMPLATE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement