c++ - 未定义对 'vtable for class' 构造函数的引用

标签 c++ class constructor

在编译以下头文件时,我得到一个未定义的对“学生 vtable”的引用:

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

我找不到这里有什么问题。

最佳答案

您是在声明一个 virtual 函数而不是定义它:

virtual void calculateCredits();

要么定义它,要么声明为:

virtual void calculateCredits() = 0;

或者简单地说:

virtual void calculateCredits() { };

阅读有关 vftable 的更多信息:http://en.wikipedia.org/wiki/Virtual_method_table

关于c++ - 未定义对 'vtable for class' 构造函数的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23255256/

相关文章:

C++ 中类似 Python 的切片操作

c++ - 无法用 C++ 将消息写入文件?

java - 无法让我的 Java 类工作

javascript - 构造函数内的循环有什么问题? [JS]

c++ - 这段 C++ 视频中的工厂类有何意义?

c++ - 如何有效地存储矩形网格?

c# - 具有相同方法的多个类 - 最佳模式

class - 在 Swift 中初始化类的首选方法

java - 什么是 Java 类的签名者?

c++ - () 和 = 在创建类实例时有什么区别?