undefined reference to 'vtable for classname' [duplicate]

帅比萌擦擦* 提交于 2019-12-20 06:34:48

问题


Possible Duplicate:
Undefined reference to vtable

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;
};

回答1:


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.


来源:https://stackoverflow.com/questions/7334269/undefined-reference-to-vtable-for-classname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!