Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #ifndef STATICARRAY_H
  2. #define STATICARRAY_H
  3.  
  4. template <typename T, int CAP>
  5. class StaticArray
  6. {
  7.  
  8. private:
  9. T values[CAP];
  10. T dummy;
  11.  
  12. public:
  13.  
  14.  
  15. StaticArray(){
  16. dummy = T();
  17. for(int i = int (); i < CAP; i++)
  18. values [i] = T();
  19.  
  20. }
  21.  
  22. int capacity()const{
  23. return CAP;
  24. //sizeof(values)/sizeof(*values);
  25.  
  26. }
  27.  
  28.  
  29. T operator [](int index)const{
  30. if(index < 0) return dummy;
  31. if(index > CAP) return dummy;
  32. return values [index];
  33. }
  34.  
  35. T& operator [] (int index){
  36. if(index < 0) return dummy;
  37. if(index >= CAP) return dummy;
  38. return values [index];
  39. }
  40.  
  41.  
  42. };
  43.  
  44. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement