c ++缺少vtable错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15265106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:13:21  来源:igfitidea点击:

c++ a missing vtable error

c++

提问by user1908860

I am getting a really weird error related to missing vtable for a given class constructor and destructor. Please help me to resolve this.

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

Undefined symbols for architecture i386:

架构 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)

Code snippet;

代码片段;

.h file:

.h 文件:

class A: public B

  public:
     A();
    ~A();

};

.cpp file..

.cpp 文件..

 A::A()   
{


}

A::~A()
{


}

回答by Bingo

Ah! Mulling over this I think I get what is happening. I'm betting that CCNodeis code which belongs to somebody else.

啊! 仔细考虑这个,我想我明白发生了什么。我打赌这CCNode是属于别人的代码。

Any virtual functions you inherit are also virtual in the derived class... and it is common practice to make the destructor virtual... you might not realise the destructor is virtual.

您继承的任何虚拟函数在派生类中也是虚拟的......并且使析构函数成为虚拟的常见做法......您可能没有意识到析构函数是虚拟的。

Also if you are using somebody else's header file, but forgot to link to their object file, it might cause this error, as the linker would be missing the destructor of CCNode.

此外,如果您正在使用其他人的头文件,但忘记链接到他们的目标文件,则可能会导致此错误,因为链接器将缺少CCNode.

回答by ravi.zombie

Found it,,trying with the sample, here is an exmaple.

找到它,尝试使用示例,这是一个示例。

class Shape{

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

virtual ~Shape(){};
};

The compiler complained

编译器抱怨

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

The modification is empty or any inline content inside {} next to the virtual function

虚函数旁边的 {} 中的修改为空或任何内联内容

class Shape{

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

    virtual ~Shape(){};
};

Basically, its not finding the function definition for the non-inline virtual functions.

基本上,它没有找到非内联虚函数的函数定义。

回答by Pihhan

Try to add virtual destructor to your class. CCNode propably contains some virtual methods and your compiler failed cope with it.

尝试将虚拟析构函数添加到您的类中。CCNode 可能包含一些虚拟方法,并且您的编译器无法处理它。

    class MissionController: public CCNode
    {

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

Is it some public framework, where can we see CCNode class definition? See vtable for .. referenced from compile error xcodeor maybe http://www.parashift.com/c++-faq-lite/link-errs-missing-vtable.htmlfor more help.

它是一些公共框架,我们在哪里可以看到 CCNode 类定义?见虚函数表的..从编译错误Xcode中引用或可能http://www.parashift.com/c++-faq-lite/link-errs-missing-vtable.html更多的帮助。