OTARRAY.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. // Filename : OTARRAY.H
  21. // Description : template for temporary array
  22. #ifndef __OTARRAY_H
  23. #define __OTARRAY_H
  24. // to create a temp. array of char[10],
  25. // TArray<char> charArray(10);
  26. // --------- define template class TArray --------//
  27. template TArray <class T>
  28. class TArray
  29. {
  30. private:
  31. T* array_ptr;
  32. int array_size;
  33. public:
  34. TArray( int s );
  35. ~TArray();
  36. T& operator[](int i) { return array_ptr[i]; }
  37. int size(); { return array_size; }
  38. };
  39. // --------- begin of function TArray::TArray --------//
  40. template TArray <class T>
  41. TArray<T>::TArray(int s) : array_ptr(new T[s]), array_size(s)
  42. {
  43. }
  44. // --------- end of function TArray::TArray --------//
  45. // --------- begin of function TArray::~TArray --------//
  46. template TArray <class T>
  47. TArray<T>::~TArray()
  48. {
  49. delete[] array_ptr;
  50. }
  51. // --------- end of function TArray::~TArray --------//
  52. #endif