mer*_*011 0 c++ operator-overloading operators bitwise-operators
我不确定这是否可行,因为据我所知,引用不能引用整数中的各个位,但我很想知道是否有一种技术可以实现以下效果.
int z = 0x1234;
z[0] = 1; //set the most significant bit of z.
uint8_t bit = z[30] //get the index 30 bit of z, counting from the left.
Run Code Online (Sandbox Code Playgroud)
如果我不能z[0] = 1,我想知道是否至少可以使用重载操作提取位.
不是直接的.你可以写一个包装器int或使用一个std::bitset.