C++ c++;丢失的可编辑错误

C++ c++;丢失的可编辑错误,c++,C++,我得到了一个非常奇怪的错误,与给定类构造函数和析构函数缺少vtable有关。请帮我解决这个问题 架构i386的未定义符号: "vtable for A", referenced from: A::A() in A.o A::~MissionController() in A.o NOTE: a missing vtable usually means the first non-inline virtual member function has no defin

我得到了一个非常奇怪的错误,与给定类构造函数和析构函数缺少vtable有关。请帮我解决这个问题

架构i386的未定义符号:

  "vtable for A", referenced from:
      A::A() in A.o
      A::~MissionController() in A.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
代码段

.h文件: .cpp文件。。
尝试将虚拟析构函数添加到类中。CCNode可能包含一些虚拟方法,您的编译器无法处理这些方法

    class MissionController: public CCNode
    {

      public:
         MissionController();
        virtual ~MissionController();
    };

它是某种公共框架,我们在哪里可以看到CCNode类定义?请查看或寻求更多帮助。

啊!仔细想想这件事,我想我明白发生了什么。我打赌
CCNode
是属于其他人的代码

您继承的任何虚拟函数在派生类中也是虚拟的。。。通常的做法是使析构函数虚拟。。。你可能没有意识到析构函数是虚拟的


另外,如果您正在使用其他人的头文件,但忘记链接到他们的目标文件,则可能会导致此错误,因为链接器将丢失
CCNode
的析构函数。找到它后,请尝试使用示例,下面是一个exmaple

class Shape{

public:
virtual int areas();
virtual void display();

virtual ~Shape(){};
};
编辑抱怨道

Undefined symbols for architecture x86_64:
"typeinfo for Shape", referenced from:
  typeinfo for trian in main_file.o
 "vtable for Shape", referenced from:
  Shape::Shape() in main_file.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)
  make: *** [cpp_tries] Error 1enter code here
修改为空或虚拟函数旁边{}内的任何内联内容

class Shape{

public:
    virtual int areas(){};
    virtual void display(){};

    virtual ~Shape(){};
};

基本上,找不到非内联虚拟函数的函数定义。

注意:缺少vtable通常意味着第一个非内联虚拟成员函数没有定义。我认为您的错误在您未发布的代码中。例如,在CCNodeAs中定义了哪些虚拟函数。编译器说,可能缺少一个虚拟函数。我经常忘记包含纯虚拟析构函数的定义,这在纯虚拟析构函数的情况下实际上是必需的。@user1908860,如果删除
CCNode
基,则不可能出现此错误,因为如果类没有虚拟函数,则不需要vtable。因此,您没有显示真正的代码,或者在更改代码后没有(重新)正确构建项目,或者您在撒谎。当我尝试重写非虚拟父方法时,我遇到了类似的错误。
Undefined symbols for architecture x86_64:
"typeinfo for Shape", referenced from:
  typeinfo for trian in main_file.o
 "vtable for Shape", referenced from:
  Shape::Shape() in main_file.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)
  make: *** [cpp_tries] Error 1enter code here
class Shape{

public:
    virtual int areas(){};
    virtual void display(){};

    virtual ~Shape(){};
};