我有以下编译得很好的代码:
void foo::bar(const vector<int> arg) {
int* ptr = arg.data();
// do something with ptr
}
我需要为 vector<bool>
重载此函数
void foo::bar(const vector<bool> arg) {
int* ptr = arg.data();
// error C2039: 'data': is not a member ofstd::vector<bool,std::allocator<_Ty>>'
// do something with ptr
}
vector<bool>
的原因是什么?没有 data()
成员(member)?
这里 ( en.cppreference.com ) 我没有找到特定于 bool
的东西案例std::vector
.
代码使用 MSVS 2015 编译。
最佳答案
整点 vector<bool>
特化是与所有其他 vector 不同,vector<bool>
中的数据不需要存储为 bool
的数组.通过在单个字节中打包多个位,可以更有效地存储它。因此,没有 bool *
可能由 data()
返回成员(member)。
关于c++ - MSVS 2015 : vector<bool> has no 'data' member,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32696636/