000
10.11.2004, 18:12 Uhr
Nick5
|
Hallo,
bei folgendem Programm erkennt mein Compiler die Deklarationen diverser Methoden nicht, z.B. print(). Kann mir jemand erklären warum? Danke.
C++: |
#include<iostream> #include<time.h>
using namespace std;
template <class T> class MergeArray{ private: T *mArray; int ALaenge; int AIndex;
public: MergeArray(int inLaenge = 50){ mArray = new T[inLaenge]; ALaenge = inLaenge; AIndex = 0; } void print(); void insert(string); void mergeSort(int, int); };
template <class T> void MergeArray::print(){ for(int i=0; i<ALaenge; i++) cout << mArray[i] << "\t"; cout << endl; }
template <class T> void MergeArray::insert(T inString){ if(AIndex <= ALaenge) mArray[AIndex++] = inString; else cout << "Das Array ist voll!" << endl; }
template <class T> void MergeArray::mergeSort(int iLeft = 0, int iRight = ALaenge-1){ const int Middle = (iLeft + iRight) / 2; const int NrElements = iLeft - iRight + 1; if(iLeft < Middle) mergeSort(iLeft, Middle); if(Middle + 1 < iRight) mergeSort(Middle+1, iRight); T* tmpArr = new T[NrElements]; for(int i=0; i<NrElements; i++) tmpArr[i] = mArray[iLeft+i]; int itmpL = 0; const int tmpMiddle = Middle - iLeft + 1; int itmpR = tmpMiddle; for(int i=iLeft; i<=iRight; i++){ mArray[i] = tmpArr[itmpL] < tmpArr[itmpR] ? tmpArr[itmpL++] : tmpArr[itmpR++]; if(itmpL == tmpMiddle){ for(++i; i <= iRight; i++) mArray[i] = tmpArr[itmpR++]; return; }else if(itmpR == NrElements){ for(++i; i <= iRight; i++) mArray[i] = tmpArr[itmpL++]; return; } } delete []tmpArr; }
int main(){ MergeArray<string> mA; srand(time(NULL)); for(int i=0; i<50; i++) mA.insert(rand() % 100 + 65); mA.print(); mA.mergeSort(); mA.print(); system("pause"); return 0; }
|
|