Hallo, zuerstmal vielen Dank für die Hilfe bei meiner letzten Frage. Jetzt sitze ich schon wieder an einem Problem. Zuerst einmal ein paar Codeschnitzel : ############### Datei SQLServerV.h #include "SQLServer.h" class Form1V : public Form1 { public : Form1V( QWidget* parent = 0 , const char* name = 0, bool modal = false, WFlags fl = 0) : Form1(parent, name, modal, fl){}; ~Form1V(){}; protected slots: virtual void slotAbb(); virtual void slotOK(); }; ##### Datei SQLServerV.cpp #include "SQLServerV.h" void Form1V::slotOK() { close(); } void Form1V::slotAbb() { close(); } ####### Datei SQLServer.h (automatisch erzeugt aus SQLServer.ui) class Form1 : public QDialog { Q_OBJECT public: Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); ~Form1(); QLabel* TextLabel1; QLineEdit* LineEdit1; QPushButton* PushButton1; QPushButton* PushButton2; protected slots: virtual void slotAbb(); virtual void slotOK(); }; # Aufruf Form1V Form1V *SQL = new Form1V(this); ################### Ich habe also eine Form erstellt, in der 2 Buttons mit slotAbb und slotOK verbunden sind. Diese sind in der generierten Datei als virtual deklariert. Also eine abgeleitete Klasse geschrieben, in der ich die beiden Funktionen überschreibe. Jetzt mein Problem : Wenn ich mit dem o.g. Aufruf auf die Klasse zugreifen will, bekomme ich von Linker die Fehlermeldung : [...] linwws.o: In function `Form1V::Form1V[in-charge](QWidget*, char const*, bool, unsigned)': /data/Entwicklung/Linux/linwws/linwws/linwws.cpp:34: undefined reference to `vtable for Form1V' /data/Entwicklung/Linux/linwws/linwws/linwws.cpp:34: undefined reference to `vtable for Form1V' collect2: ld returned 1 exit status gmake[3]: *** [linwws] Fehler 1 [...] In der Docu habe ich dazu nichts gefunden. Über google fand ich den Tipp in dem Destructor etwas auszuführen. Also einen Zeiger mit new initialisiert und im Destr. mit delete den Speicher wieder freigegeben. Der Erfolg war, das ich die Fehlermeldung 4x bekommen habe. Wenn ich den Konstructor von Form1V ohne Parmeter aufrufe, dann iat die Fehlermeldung weg; nur das ist ja nicht Sinn der Sache. Also was ist "vtable for" ? So langsam frage ich mich warum ich jetzt schon 10 Jahre in c bzw c++ programmiere.. ;-(( Schon mal vielen Dank für Eure Hilfe Jörg -- Jörg Frings-Fürst 54526 Landscheid http://www.fixundfoxi.dydndns.info -- Registered Linux User # 280687 GPG Key ID : 9E5F BE06 E208 BAA3 GPG Fingerprint : 4F77 0BBE 4148 5D92 600F 7BF3 9E5F BE06 E208 BAA3
Joerg Frings-Fuerst
linwws.o: In function `Form1V::Form1V[in-charge](QWidget*, char const*, bool, unsigned)': /data/Entwicklung/Linux/linwws/linwws/linwws.cpp:34: undefined reference to `vtable for Form1V' /data/Entwicklung/Linux/linwws/linwws/linwws.cpp:34: undefined reference to `vtable for Form1V' collect2: ld returned 1 exit status gmake[3]: *** [linwws] Fehler 1 [...]
Vorab will ich nur anmerken, dass ich kein C++ Programmierer bin und meine C++ Kenntnisse sind daher beschränkt sind.
Also was ist "vtable for" ?
Was ein Vtable (virtual table) ist, solltest du eigentlich wissen, wenn du seit 10 Jahren C++ programmierst :) Aber vielleicht hilft dir der folgende Abschnitt aus der gcc FAQ http://gcc.gnu.org/faq.html#vtables : ---------------------------------------------------- When building C++, the linker says my constructors, destructors or virtual tables are undefined, but I defined them. The ISO C++ Standard specifies that all virtual methods of a class that are not pure-virtual must be defined, but does not require any diagnostic for violations of this rule [class.virtual]/8. Based on this assumption, GCC will only emit the implicitly defined constructors, the assignment operator, the destructor and the virtual table of a class in the translation unit that defines its first such non-inline method. Therefore, if you fail to define this particular method, the linker may complain about the lack of definitions for apparently unrelated symbols. Unfortunately, in order to improve this error message, it might be necessary to change the linker, and this can't always be done. The solution is to ensure that all virtual methods that are not pure are defined. Note that a destructor must be defined even if it is declared pure-virtual [class.dtor]/7. ----------------------------------------------- Sprich alle virtuellen Methoden müssen, soweit sie nicht 'pure virtual' sind, definiert werden. In wieweit das für deinen Code zutrifft, musst du selbst entscheiden, denn das übersteigt meine Kenntnisse. Philipp -- Philipp Thomas Arbeit: pthomas@suse.de Entwicklung, SuSE Linux AG Privat: pth@t-link.de
participants (2)
-
Joerg Frings-Fuerst
-
Philipp Thomas