【问题标题】:C++ std::vector<bool> gives uninitialized read error using drmemoryC++ std::vector<bool> 使用 drmemory 给出未初始化的读取错误
【发布时间】:2013-10-21 23:43:41
【问题描述】:

我在我的项目中使用了 stl 容器,我发现了一个我无法解释的奇怪错误。让我们考虑以下代码:

#include <iostream>
#include <vector>

int main(int argc, char** argv)
{
    std::vector<bool> vec;
    vec.resize(5, false);
    std::cout << vec.at(0);
}

这会按预期输出 0,但如果我使用 drmemory 运行内存检查,它会发现未初始化的读取。任何人都可以帮助理解这种行为吗?

平台:win32; 编译器:mingw32 - gcc 4.7.2; Drmemory 1.6.0 - 构建 2

【问题讨论】:

  • vector&lt;bool&gt; 很奇怪。

标签: c++ stl dr-memory


【解决方案1】:

std::vector&lt;bool&gt; 是个奇怪的小东西,用比特玩弄来达到目的。在这种情况下,我很乐意建议您所看到的只是一条红鲱鱼。

话虽如此,you might be better off with some other container,因为this template specialisation is universally despised

【讨论】:

    猜你喜欢
    • 2013-06-06
    • 2016-09-20
    • 2014-09-13
    • 1970-01-01
    • 2012-02-07
    • 2017-04-17
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多