undefined reference to 'vtable for class' constructor [duplicate]

I am getting an undefined reference to `vtable for student' while compiling the following header file:

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(){}

I can't find what is wrong in this.

0

1 Answer

You're declaring a virtual function and not defining it:

virtual void calculateCredits();

Either define it or declare it as:

virtual void calculateCredits() = 0;

Or simply:

virtual void calculateCredits() { };

Read more about vftable:

3

You Might Also Like