我正在尝试编译 FBreader 库以用于我的项目。两个 .so 库已成功编译,但在最后一个库中出现以下错误
jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp:42:31: error: default initialization of an object of const type 'const XHTMLTagInfoList' without a
user-provided default constructor
static const XHTMLTagInfoList EMPTY_INFO_LIST;
^
查看c++代码后,下面是发生错误的行
static const XHTMLTagInfoList EMPTY_INFO_LIST;
XHTMLTagInfoList
变量是
const XHTMLTagInfoList &XHTMLReader::tagInfos(size_t depth) const {
if (myTagDataStack.size() < depth + 2) {
return EMPTY_INFO_LIST;
}
return myTagDataStack[myTagDataStack.size() - depth - 2]->Children;
}
我不太擅长 C++。请帮助解决错误
更新为 static const XHTMLTagInfoList EMPTY_INFO_LIST{};
发生以下错误
最佳答案
我会引用这个answer :
C++ 标准(第 8.5 节)说:
If a program calls for the default initialization of an object of a const-qualified type T, T shall be a class type with a user-provided default constructor.
如果我们转到 XHTMLTagInfoList definition我们会看到它确实没有用户定义的构造函数。
要解决您的问题,您只需要使用空的初始值设定项:
static const XHTMLTagInfoList EMPTY_INFO_LIST{};
注意,非常量声明不需要它
编辑:请注意,您很可能没有启用 -std=c++11,这将修复您的错误
关于c++ - 为 FBReader 编译 NDK 库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41170320/