我认为你混淆了两件事.
在bitset类存储的位在一个紧凑的表示,例如,一个在char阵列中,通常每8位char(但YMMV上的"外来的"平台).
所述bitset::reference类被提供以允许用户bitset类具有参考状物体存储在比特bitset.
因为常规指针和引用没有足够的粒度来指向存储在其中的单个位bitset(它们的最小粒度是char),所以这样的类模仿了对位上的伪引用类左值操作的引用的语义.特别是,这需要允许返回的值operator[]"正常"作为左值(并且它可能构成其"正常"使用的99%).在这种情况下,它可以被视为"代理对象".
通过重载赋值运算符和转换为bool运算符来实现此行为; 的bitset::reference类可能将封装到父的参考bitset对象和引用位的偏移量(字节+位),即用于由这样的操作员检索和存储的位的值.
- -编辑 - -
实际上,g ++实现使bitset::reference存储直接指向存储字节的存储器字的指针,以及这种字中的位号.然而,这只是一个提高其性能的实现细节.
顺便说一句,在图书馆的资料中,我发现了一个非常紧凑但清晰的解释bitset::reference:它是什么以及它做了什么:
/**
* This encapsulates the concept of a single bit. An instance of this
* class is a proxy for an actual bit; this way the individual bit
* operations are done as faster word-size bitwise instructions.
*
* Most users will never need to use this class directly; conversions
* to and from bool are automatic and should be transparent. Overloaded
* operators help to preserve the illusion.
*
* (On a typical system, this <em>bit %reference</em> is 64
* times the size of an actual bit. Ha.)
*/
Run Code Online (Sandbox Code Playgroud)