SHARE
TWEET

Untitled

a guest Jun 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template <typename T>
  2. class MyArray {
  3. private:
  4.     T *array;
  5.     std::size_t size;
  6.     unsigned index;
  7. public:
  8.     explicit MyArray(std::size_t);
  9.     MyArray(const MyArray&);
  10.     ~MyArray();
  11.     void pushBack(T);
  12.     T& operator[](std::size_t);
  13. }
  14.      
  15. template<typename T>
  16. MyArray<T>::MyArray(const MyArray& arr) {
  17.     index = arr.index;
  18.     size = arr.size;
  19.     for(unsigned int i = 0; i < size; i++) {
  20.         array[i] = arr.array[i];
  21.     }
  22. }
  23.  
  24. template class MyArray<int>;
  25. template class MyArray<std::string>;
  26. template class MyArray<double>;
  27.      
  28. template<typename T>
  29. MyArray<T>::MyArray(std::size_t s) : size(s) {
  30.     array = new T[size];
  31.     index = 0;
  32. }
  33.      
  34. MyArray<int> intArray(5);
  35. for (unsigned i = 0; i < 5; i++) intArray.pushBack(2);
  36.     std::cout << intArray[2] << std::endl;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top