在编译以下头文件时,我得到一个未定义的对“学生 vtable”的引用:
学生.h
class student
{
private:
string names;
string address;
string type;
protected:
float marks;
int credits;
public:
student();
student(string n,string a,string t,float m);
~student();
string getNames();
string getAddress();
string getType();
float getMarks();
virtual void calculateCredits();
int getCredits();
};
student::student(){}
student::student(string n, string a,string t,float m)
{
names = n;
address = a;
marks = m;
}
student::~student(){}
我找不到这里有什么问题。
最佳答案
您是在声明一个 virtual
函数而不是定义它:
virtual void calculateCredits();
要么定义它,要么声明为:
virtual void calculateCredits() = 0;
或者简单地说:
virtual void calculateCredits() { };
阅读有关 vftable 的更多信息:http://en.wikipedia.org/wiki/Virtual_method_table
关于c++ - 未定义对 'vtable for class' 构造函数的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23255256/