问题描述:
"vtable for XXX", referenced from:
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
原因:
1:是不是有纯虚函数没有实现
2:iOS C++中,纯虚函数中,要求非纯虚函数都必须得实现,检查是否有没有实现的虚函数.
错误代码如下:
class Foo {
virtual void f();
virtual void s() = 0;
};
class Rice {
Rice(){};
~Rice(){};
virtual void f(){};
virtual void s(){};
}
int main(int argc, char **argv)
{
Rice rice;
return(0);
}
修改:
class Foo {
virtual void f() = 0;
virtual void s() = 0;
};
或:
class Foo {
virtual void f(){};
virtual void s() = 0;
};NOTE:
The ISO C++ Standard specifies that all virtual methods of a class that are not pure-virtual must be defined, but does not require any diagnostic for violations of this rule [class.virtual]/8. Based on this assumption, GCC will only emit the implicitly defined constructors, the assignment operator, the destructor and the virtual table of a class in the translation unit that defines its first such non-inline method.
Therefore, if you fail to define this particular method, the linker may complain about the lack of definitions for apparently unrelated symbols. Unfortunately, in order to improve this error message, it might be necessary to change the linker, and this can't always be done.
本文探讨了编译链接错误“vtableforXXX”产生的原因,通常由于未实现纯虚函数导致。介绍了如何检查并修正此类错误,确保所有非纯虚函数得到正确实现。

4013

被折叠的 条评论
为什么被折叠?



