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

问题描述

我想知道为什么我得到这个错误:
未定义的引用`vtable为BaseRenderer'

I was wondering why I was getting this error:undefined reference to `vtable for BaseRenderer'

我试图搜索,但似乎无法计算出来。我尝试摆脱虚拟函数,删除构造函数等。

I tried searching around but cannot seem to figure this out. I've tried getting rid of the virtual function, removing the constructor, etc.

我的BaseRenderer.h

My BaseRenderer.h

class BaseRenderer : public Renderer
{
 Q_OBJECT

    public:
        BaseRenderer();
        BaseRenderer(QWidget *parent);
        void paintGL();

        virtual ~BaseRenderer();

 public slots:
  void loadDialog();

 signals:

    protected:
        Mesh loadMesh(string fileName);

    private:

        OBJParser objParser;
        Mesh baseTerrain;

};

我的BaseRenderer.cpp

My BaseRenderer.cpp

BaseRenderer::BaseRenderer()              <------ Error leads me here
{
}

BaseRenderer::BaseRenderer(QWidget *parent) : Renderer(parent)
{

}

BaseRenderer::~BaseRenderer()
{
    //dtor
}

如何摆脱这个问题?我也听说它可能是编译器...?
感谢您的帮助:)

How would I go about getting rid of this issue? I also hear it may be the compiler...?Thanks for the help :)

推荐答案

由于Q_OBJECT在父类Renderer中,还包括它BaseRenderer。只是摆脱Q_OBJECT,它应该工作:)

Since Q_OBJECT is in the parent class, Renderer, you don't have to also include it BaseRenderer. Just get rid of Q_OBJECT and it should work :)

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

06-28 19:48