Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #ifndef X
  2. #define X
  3. #include <iostream>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. template <class T> class Dane;
  8. template <class T> ostream & operator << (ostream & os,const Dane<T> & d);
  9.  
  10.  
  11. template <class T>
  12. class Dane
  13. {
  14. private:
  15. T *t;
  16. int N;
  17. public:
  18. Dane();
  19. Dane(int n , T max);
  20. ~Dane();
  21. friend ostream &operator << <> (ostream & os, const Dane <T> & d);
  22. // void operator () <>(T num, int i);
  23.  
  24.  
  25. };
  26.  
  27.  
  28.  
  29.  
  30. template <class T>
  31. Dane<T>::Dane()
  32. {
  33. N=1;
  34. t = new T[N];
  35. t[0] = T(0);
  36. }
  37.  
  38. template <class T>
  39. Dane<T>::Dane(int n, T max)
  40. {
  41. N=n;
  42. t = new T[N];
  43. for(int i = 0 ; i <N ; i++ ) t[i] = T(max*rand()/(RAND_MAX+1));
  44.  
  45. }
  46.  
  47. template <class T>
  48. Dane<T>::~Dane()
  49. {
  50. delete [] t;
  51.  
  52. }
  53.  
  54. template <class T>
  55. ostream & operator <<(ostream & os , const Dane<T> & d)
  56. {
  57. os << "[ ";
  58. for(int i = 0 ; i <d.N; i++ ) os << d.t[i] << " ";
  59. os <<"]" << endl;
  60. return os;
  61. }
  62.  
  63. /*template <class T>
  64. void Dane<T>::operator ()(T num, int i)
  65. {
  66. *this(i) = num;
  67. }*/
  68.  
  69.  
  70. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement