01 // Feldklasse/statischer Speicher
02 // Datei: feld3.h
03 #include <stdlib.h>
04
05 template <class TYP, int anzahl>
06 class feld
07 {
08 int maxindex;
09 TYP puffer[anzahl];       // statisches Feld
10 public:
11 TYP & operator [](int index);
12 feld ();
13 ~feld();
14 };
15
16 template <class TYP, int anzahl>
17 feld<TYP,anzahl>::feld()   // Konstruktor
18 {
19 maxindex = anzahl -1;
20 }
22 template <class TYP,int anzahl>
23 feld<TYP,anzahl>::~feld()    // Destruktor
24 {
25 }
27 template <class TYP, int anzahl> // Feldoperator
28 TYP & feld<TYP,anzahl>::operator[] (int index)
29 {
30 if (index < 0 || index > maxindex)
31    exit(1);
32 return puffer[index];
33 }
34

Bild 17-14  Klasse mit statischem Feld