Tar*_*nen 41 c++ constructor class
在编译以下头文件时,我得到了一个未定义的引用"vtable for student":
student.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(){}
Run Code Online (Sandbox Code Playgroud)
我找不到这个有什么问题.
小智 77
您正在声明一个virtual函数而不是定义它:
virtual void calculateCredits();
定义它或将其声明为:
virtual void calculateCredits() = 0;
或者干脆:
virtual void calculateCredits() { };
阅读更多关于vftable的信息:http://en.wikipedia.org/wiki/Virtual_method_table