Seite 1 von 1

Auf Methoden abgeleiteter Template-Klassen zugreifen

Verfasst: 10. Oktober 2008 20:17
von Bronski
Hallo,
Ich bin Neuling im Programmieren mit C++ und Qt. Erfahrung mit objekt orientierten Programmieren hatte ich bislang nur in Delphi.
Ich möchte eine Template - Klasse von der Klasse QList ableiten.
Nun meine (vielleicht dumme) Frage:

Wie greife ich auf die öffentlichen Elementfunktionen (Methoden) und Elemente der Basisklasse QList von der abgeleiteten Klasse zu ?

Code: Alles auswählen

#include <QApplication>
#include <stdio.h>
#include <stdlib.h>

template <class T> class Tset : public  QList <T> 
{
public :
 void Sort()
 {

 qSort(begin(),end());// Das funktioniert nicht !!!!
 // Wie kann ich von hier aus auf Funktionen und Elemente von QList 
 // zugreifen ?
 }
};



Code: Alles auswählen



#ifdef HAVE_CONFIG_H
#include <config.h>
#endif



#include <stdio.h>
#include <stdlib.h>
#include <QApplication>
#include "./davids_math.h"
#include <iostream>

int main(int argc, char *argv[])
{
int x;
Tset <int> liste;

liste.append(1001);
liste.append(1008);
liste.append(1006);


for(x=0;x<3;++x)
{
printf("%d\n", liste[x]) ;
}

//qSort(liste);
liste.Sort(); // Das funktioniert nicht !!!!

for(x=0;x<3;++x)
{
printf("%d\n", liste[x]) ;
}

  return EXIT_SUCCESS;
}
Vielen Dank im Voraus für eure Bemühungen. :)

Verfasst: 10. Oktober 2008 21:20
von upsala
Auch in Delphi dürfte 'Funktioniert nicht' keine Fehlermeldung sein...

Verfasst: 11. Oktober 2008 20:39
von Bronski
Also, der Compiler gibt mir folgende Fehlermeldungen aus:

Code: Alles auswählen

./davids_math.h: In member function ‘void Tset<T>::Sort()’:
./davids_math.h:30: error: there are no arguments to ‘begin’ that depend on a template parameter, so a declaration of ‘begin’ must be available
./davids_math.h:30: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
./davids_math.h:30: error: there are no arguments to ‘end’ that depend on a template parameter, so a declaration of ‘end’ must be available
davids_math.cpp: At global scope:
davids_math.cpp:34: warning: unused parameter ‘argc’
davids_math.cpp:34: warning: unused parameter ‘argv’
gmake: *** [davids_math.o] Fehler 1
*** Beendet mit Status: 2 ***


Verfasst: 11. Oktober 2008 21:44
von upsala
Letzter Absatz

Code: Alles auswählen

qSort(this->begin(), this->end());

Verfasst: 11. Oktober 2008 23:02
von Bronski
Das hat funktioniert.
Vielen Dank :P