#define BUFF_ENT_MAX 10 using namespace std; template class RingBuf { public: RingBuf(int Gr = BUFF_ENT_MAX); RingBuf(const RingBuf& other); ~RingBuf(); RingBuf& operator=(const RingBuf& other); T& operator[](int i); void store(T& toAdd); int find(T& toFind); private: int size; T* theData; }; /* direkt folgend: Funktionsimplementierung */ template RingBuf::RingBuf(int Gr) { // erstellt RingBuf mit Daten vom Typ T if(Gr < 1 || Gr > 100) Gr = BUFF_ENT_MAX; size = Gr; theData = new T [size]; for(int i=0; i RingBuf::~RingBuf() { delete[] theData; } template RingBuf::RingBuf(const RingBuf& Other) { size = Other.size; theData = new T[size]; for(int i = 0; i < size; i++) theData[i] = Other.theData[i]; } template RingBuf& RingBuf::operator=(const RingBuf& Other) { delete[] theData; theData = new T[Other.size]; size = Other.size; for(int i = 0; i < size; i++) theData[i] = Other.theData[i]; return *this; } template T& RingBuf::operator[](int i) { if(i < size && i >= 0) return theData[i]; else { terminate(); } } template void RingBuf::store(T& toAdd) { // fuegt Daten in Puffer (am Ende) ein for(int i = size - 1; i >= 1; i--) { theData[i-1] = theData[i]; } theData[0] = toAdd; } template int RingBuf::find(T& toFind) { // sucht Daten im Puffer int foundAt = -1; for(int i = 0; i < size && foundAt != -1; i++) { if(theData[i] == toFind) foundAt = i; } return foundAt; } ------------------------------------------------------------------------- #include #include #include "templateT.h" using namespace std; int main() { RingBuf RInt(20); int y = 5; //int i = RInt[4]; RInt.store(y); cout << "Hallo, du:: \n" << RInt[0] << endl; }