boost - 尝试访问 dynamic_bitset 中的私有成员
问题描述
我正在使用 Visual Studio 2017 构建 LucenePlusPlus,而后者又使用 boost/dynamic_bitset。
LucenePlusPlus 中的以下代码
const uint64_t* BitSet::getBits() {
return bitSet.empty() ? NULL : static_cast<const uint64_t*>(&bitSet.m_bits[0]);
}
生成以下致命编译器错误:
1>g:\luceneplusplus\src\core\util\bitset.cpp(20): error C2248: 'boost::dynamic_bitset<uint64_t,std::allocator<Block>>::m_bits': cannot access private member declared in class 'boost::dynamic_bitset<uint64_t,std::allocator<Block>>'
1> with
1> [
1> Block=uint64_t
1> ]
建议?
解决方案
我已经跟踪了我的 boost 1_75_0 的代码,我看到它有一个定义,可以有条件地保留对朋友的访问权限:
#if defined(BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS)
#define BOOST_DYNAMIC_BITSET_PRIVATE public
#else
#define BOOST_DYNAMIC_BITSET_PRIVATE private
#endif
所以看起来你应该能够添加-DBOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
到编译器定义来解决这个问题。
事实上,我的 LucenePlusPlus 树已经包含在 include/config_h/Config.h.in 第 107 行中:
#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
以前(“重建的 cmake 构建系统”)这显然来自 include/Config.h.cmake,它始终存在,自 2010 年以来一直无条件地存在:
你能做什么?
也许您没有包含包含配置的必需标头?还要检查任何干扰的预编译头设置。
如果您boost/dynamic_bitset.hpp
在任何时候都包含了 LucenePlusPlus 标头,那么您将使用错误的配置运行。
如果您没有检测到它,这尤其糟糕,因为这会违反 ODR 规则
推荐阅读
- ios - 在没有 PODS 的 iOS 项目中集成 Firebase Crashlytics (beta) SDK
- javascript - 在制表器中显示行数
- sapui5 - 访问属性并更改其值
- python - Python Cucumber BDD 包:注入您想要测试的功能的惯用方式
- windows - 如何强制 Windows 检测通过直接写入物理扇区创建的 BitLocker 卷
- r - 使用ggparty根据终端节点的值旋转决策树分支
- reactjs - TypeScript 返回与泛型参数具有相同属性的对象
- python - python文件读取错误jsonfile,有人可以帮我解决这个问题
- assembly - MIPS/Assembly 如何在错误时重复输入
- sql - 具有匹配资产数量的 SQL 分析查询