I tried to compile a class with virtual functions and qtcreator want only compile the functions inside the header. I cannot compîle when the functions are in the cpp file. The compilator says the vtable is not defined.
I tried to compile a class with virtual functions and qtcreator want only compile the functions inside the header. I cannot compîle when the functions are in the cpp file. The compilator says the vtable is not defined.
shenakan (25th August 2009)
Qt Code:
#ifndef PATH_H #define PATH_H #include <fstream> #include <iostream> #include <sstream> #include <iomanip> using namespace std; class Path{ protected: public: virtual double getOrientation() const; }; #ifndef TRANSIT_H #define TRANSIT_H #include <iomanip> #include <fstream> #include <iostream> #include <string.h> #include "path.h" using namespace std; class Transit : public Path{ public: Transit(const char *info); double getOrientation() const; }; #endifTo copy to clipboard, switch view to plain text mode
I get this message : undefined reference to "vtable for Path"
ok I found my problem. I forgot to add =0 at the end of my virtual function and also a const in one of function of the derivated class.
Qt Code:
virtual double getOrientation() const = 0;To copy to clipboard, switch view to plain text mode
the defination looks alrite to me.... are you defining function in both the classes?
EDIT: - too late
If you don't want the "getOrientation()" method to be virtual pure ( = 0 ), you could also define a virtual destructor for the Path class.
Bookmarks