链接错误缺少 vtable [英] Link error missing vtable

查看:37
本文介绍了链接错误缺少 vtable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在定义一个类函数"和另外两个继承自函数"的类多项式"和仿射".

I'm defining a class 'function' and two others classes 'polynomial' and 'affine' that inherit from 'function'.

    class function {

    public:
        function(){};
        virtual function* clone()const=0;
        virtual float operator()(float x)const=0; //gives the image of a number by the function
        virtual function* derivative()const=0;
        virtual float inverse(float y)const=0; 
        virtual ~function(){}

    };

    class polynomial : public function {
    protected:
        int degree;
    private:
        float *coefficient;
    public:

        polynomial(int d);
        virtual~polynomial();
        virtual function* clone()const;
        int get_degree()const;
        float operator[](int i)const; //reads coefficient number i
        float& operator[](int i); //updates coefficient number i
        virtual float operator()(float x)const; 
        virtual function* derivative()const;
        virtual float inverse(float y)const; 

    };

    class affine : public polynomial {
        int a; 
        int b; 
        //ax+b
public:
        affine(int d,float a_, float b_);
        function* clone()const;
        float operator()(float x)const;
        function* derivative()const;
        float inverse(float y)const;
        ~affine(){}
    };

我实现了所有与多项式"相关的方法,并想测试它们.对于派生方法,我在实例的度数等于 0 的情况下使用仿射构造函数.所以我必须在运行测试之前定义这个构造函数.

I implemented all the methods relating to 'polynomial' and would like to test them. For the derivative method, I'm using the affine constructor in the case the instance's degree is equal to 0. So I have to define this constructor before running tests.

polynomial::polynomial(int d)
{
    assert(d>=0);
    degree=d;
    coefficient=new float [d+1];
}

polynomial::~polynomial()
{
    delete[] coefficient;
}
function* polynomial::derivative()const
{
    if(degree==0)
    {
        return new affine(0,0,0);
    }
    polynomial* deriv=new polynomial(degree-1);
    for(int i=0;i<degree;i++)
        deriv[i]=(i+1)*coefficient[i+1];   
    return deriv;
}

affine::affine(int d,float a_, float b_):polynomial(d)
{ 
    assert(d==0 || d==1);
    degree=d;
    a=a_;
    b=b_;
}

我的第一个测试是:

#include "function.h"

int main(int argc, const char * argv[])
{
    //p=x^3
    polynomial p(3); 
    for(int i=0;i<=2;i++) p[i]=0;
    p[3]=1;
    cout<<"21^(1/3)="<<p.inverse(21);



    return 0;
}

当我运行它时,我收到一个链接错误:

When I run it, I get a link error :

Undefined symbols for architecture x86_64:
  "vtable for affine", referenced from:
      affine::affine(int, float, float) in polynomial.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我不知道为什么.

推荐答案

正如你们所说,这是关于仿射"的未定义覆盖方法.

As you guys said, it was about the non defined overriding methods of 'affine'.

这篇关于链接错误缺少 vtable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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