01 // Codeschablonen - Feldklasse
02 // Datei: feld1.h
03 #include <stdlib.h>
04
05 template <class TYP>
06 class feld // Beispiel für Container
07 {
08 int
maxindex;
09 TYP * puffer; // unabhängig von TYP
10 public:
11 TYP & operator
[](int index);
12 feld (int anzahl);
13 ~feld();
14 };
15
16 template <class
TYP> // Konstruktor
17 feld<TYP>::feld (int anzahl)
18 {
19 if (anzahl > 0)
20
{
21 maxindex = anzahl -1;
22 puffer = new TYP[anzahl];
23 }
24 else
25 maxindex
= -1;
26 }
27
28 template <class TYP>
29 feld<TYP>::~feld() // Destruktor
30
{
31 delete [] puffer;
32 }
3