View Full Version : virtual function
shenakan
25th August 2009, 09:02
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.
nish
25th August 2009, 09:04
can you show some code?
shenakan
25th August 2009, 09:36
#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;
};
#endif
I get this message : undefined reference to "vtable for Path"
shenakan
25th August 2009, 09:47
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.
virtual double getOrientation() const = 0;
nish
25th August 2009, 09:47
the defination looks alrite to me.... are you defining function in both the classes?
EDIT: - too late
Baltimore
26th August 2009, 09:25
If you don't want the "getOrientation()" method to be virtual pure ( = 0 ), you could also define a virtual destructor for the Path class.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.