c++ - MSVS 2015 : vector<bool> has no 'data' member

标签 c++ c++11 visual-studio-2015 std stdvector

我有以下编译得很好的代码:

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/

相关文章:

c++ - 函数作为模板参数

c++ - 为什么在使用 g++ 4.8.4 时,此代码会生成具有单个元素的 map ?

c++ - 为什么 `std::initializer_list` 不提供下标运算符?

visual-studio-2015 - 如何为 UWP 应用程序启用 "Application Timeline"?

Gale-Shapley算法的C++实现

python - 无法在 Windows 10 中构建 V8

c++ - 通过C++程序更改本地时间

C++ 无效参数,候选为 : ".." on Setters from different classes

C++ ShellExecuteEx 不会通过不从该 exe 生成输出来执行带参数的 exe

c# - Visual Studio 2015 社区 - 调试器表现奇怪