0

我在 unordered_map 中有一组位集指针

static unordered_map< size_t, bitset<BITSIZE>* > systemBits;

我的功能

template<typename system>
     static bitset<BITSIZE> & getBitFor() {

    size_t hash = typeid(system).hash_code();

    bitset<BITSIZE> * bit = systemBits[hash];

    if(bit == NULL) {
        bit = new bitset<BITSIZE>(0);
        (*bit) << POS++; // tried *bit << POS++ as well;
        systemBits[hash] = bit;
    }

    return *bit;
}

而 POS 最初是一个 int 设置为 1。

我要做的就是用每个新位集的位置量来移动位集。

 (*bit) << POS++;

但是,这似乎不起作用。当我cout返回的位集时,它的所有位都设置为 0。如果我执行以下操作:

bit->flip();

或 (*bit).flip();

返回的位集确实将所有 0 翻转为 1。

是什么赋予了?为什么移位运算符根本没有效果?

4

1 回答 1

0

因为您没有将结果分配给任何东西。如果你试图转移一个 int,你会遇到同样的问题。

此外,您已将 bitset 初始化为零,并且零移位任意量始终为零。

于 2012-06-26T08:43:33.037 回答