gpt4 book ai didi

c++ 缺少 vtable 错误

转载 作者:IT老高 更新时间:2023-10-28 22:38:40 28 4
gpt4 key购买 nike

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

架构 i386 的 undefined symbol :

  "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 文件:

class A: public B

public:
A();
~A();

};

.cpp 文件..

 A::A()   
{


}

A::~A()
{


}

最佳答案

找到了,试了下样例,这里有一个例子。

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(){};
};

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

关于c++ 缺少 vtable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15265106/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com