undefined reference to 'vtable for class' constructor

C++ClassConstructor

C++ Problem Overview


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.

C++ Solutions


Solution 1 - C++

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: http://en.wikipedia.org/wiki/Virtual_method_table

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTarounenView Question on Stackoverflow
Solution 1 - C++user1551592View Answer on Stackoverflow