未定义对"vtable for classname"的引用 [英] undefined reference to 'vtable for classname'

查看:306
本文介绍了未定义对"vtable for classname"的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
对vtable的未定义引用

Possible Duplicate:
Undefined reference to vtable

我的文件上有一个学生类-student.h 这是它的构造函数:

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

然后我得到错误:

对"vtable for Student"的未定义引用

undefined reference to 'vtable for Student'

出什么问题了?

这是一个University.h文件:

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. 将下划线放在变量名之后.以开头的名字 下划线可能被编译器使用.
  2. 如果计划,请确保至少定义一个虚函数 从它继承或使用RTTI. (例如虚拟析构函数)
  3. 确保每个声明的函数都有一个对应的 实施.
  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.

这篇关于未定义对"vtable for classname"的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆