Friday, January 4, 2019

c++ - undefined reference to 'vtable for classname'











I have a class Student on the file - student.h
and this is its constructor:



class Student
{
protected:
double _id;
double _salary;

double _grade_average;

public:
Student(double id, double salary,double average):
_id(id),_salary(salary),_grade_average(average)
{}
};


And then I get the error:





undefined reference to 'vtable for Student'




What is the problem?



this is a University.h file:



 #include "Student.h"

class University : public Student
{
public:
virtual double getValue();
University(char university_id,double id, double average,double salary):
_university_id(university_id),Student(id,average,salary)
{
}

private:

char _university_id;
static double how_many;
static double sum_avg_grades;
};

Answer



A couple of things.




  1. Put the underscore after the variable name. As names that start with

    an underscore may be used by the compiler.

  2. Make sure to define at least one virtual function if you plan on
    inheriting from it or using RTTI. (ex. a Virtual Destructor)

  3. Make sure that every declared function has a corresponding
    implementation.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...