Why am I getting “Undefined symbols … typeinfo … vtable” with a virtual and concrete class?

假如想象 提交于 2019-12-05 10:59:40

The problem is you provide no implementation for Node::step(). If you truly wish for Node to have no implementation for step, then you should make it a purely virtual function Node::step(int count) = 0, thereby making Node an abstract class (you can not directly instantiate it). Otherwise, define an implementation for Node::step.

As far as I can tell, I have defined the "first non-inline virtual member function" (i.e. TestNode::step()).

You seem to be confusing definition with declaration. What you have in the base class is only declaration without definition, i.e. implementation.

You either need to make it pure virtual or implement it even if it is just an empty {}.

class Node {
public:
    virtual Node& step(int count);
 };

The quick workaround could be:

class Node {
public:
    virtual Node& step(int count) = 0;
                               // ^^^ making it pure virtual
 };

or:

class Node {
public:
    virtual Node& step(int count) { };
                               // ^^^ empty implementation for now
 };
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!