对于给定的类构造函数和析构函数,我收到了一个与缺少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文件:
class A: public B
public:
A();
~A();
};.cpp文件..
A::A()
{
}
A::~A()
{
}发布于 2016-02-03 10:32:01
找到了,试着用样本,这是一个例子。
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(){};
};基本上,它找不到非内联虚函数的函数定义。
发布于 2013-03-07 18:31:53
阿!考虑到这一点,我想我知道发生了什么。我敢打赌,CCNode是属于别人的代码。
您继承的任何虚函数在派生类中也是虚的...通常的做法是让析构函数成为虚拟的.你可能没有意识到析构函数是虚拟的。
此外,如果您正在使用其他人的头文件,但忘记链接到他们的目标文件,则可能会导致此错误,因为链接器将缺少CCNode的析构函数。
发布于 2013-03-07 18:18:46
尝试将虚拟析构函数添加到类中。CCNode可能包含一些虚方法,但您的编译器无法处理它。
class MissionController: public CCNode
{
public:
MissionController();
virtual ~MissionController();
};它是一个公共框架吗?我们在哪里可以看到CCNode类的定义?有关更多帮助,请参阅vtable for .. referenced from compile error xcode或http://www.parashift.com/c++-faq-lite/link-errs-missing-vtable.html。
https://stackoverflow.com/questions/15265106
复制相似问题