我得到一个非常奇怪的错误,与给定的类构造函数和析构函数缺少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)
Run Code Online (Sandbox Code Playgroud)
代码段;
class A: public B
public:
A();
~A();
};
Run Code Online (Sandbox Code Playgroud)
A::A()
{
}
A::~A()
{
}
Run Code Online (Sandbox Code Playgroud)
啊! 考虑到这一点,我想我得到了正在发生的事情.我打赌这CCNode是属于别人的代码.
您继承的任何虚函数在派生类中也是虚拟的......通常的做法是将析构函数设置为虚拟...您可能没有意识到析构函数是虚拟的.
此外,如果您使用其他人的头文件,但忘记链接到他们的目标文件,它可能会导致此错误,因为链接器将缺少析构函数CCNode.
找到它,尝试样品,这里是一个例子.
class Shape{
public:
virtual int areas();
virtual void display();
virtual ~Shape(){};
};
Run Code Online (Sandbox Code Playgroud)
编译器抱怨道
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
Run Code Online (Sandbox Code Playgroud)
修改为空或虚拟函数旁边的{}内的任何内联内容
class Shape{
public:
virtual int areas(){};
virtual void display(){};
virtual ~Shape(){};
};
Run Code Online (Sandbox Code Playgroud)
基本上,它没有找到非内联虚函数的函数定义.
尝试将虚拟析构函数添加到您的类中。CCNode 可能包含一些虚拟方法,而您的编译器无法处理它。
class MissionController: public CCNode
{
public:
MissionController();
virtual ~MissionController();
};
Run Code Online (Sandbox Code Playgroud)
是一些公共框架吗,我们在哪里可以看到CCNode类的定义?请参阅从编译错误 xcode 引用的 vtable或http://www.parashift.com/c++-faq-lite/link-errs-missing-vtable.html以获得更多帮助。
| 归档时间: |
|
| 查看次数: |
30428 次 |
| 最近记录: |