如您所见,我的类有以下私有变量,包括一个 const 静态变量:
private:
// class constant for # of bits in an unsigned short int:
const static int _USI_BITS = sizeof(usi)*CHAR_BIT;
usi* _booArr;
int _booArrLen;
int _numBoos;
我是使用复制构造函数的新手,我不知道如何编写一个。这是我的尝试:
BitPack::BitPack(const BitPack& other) {
_USI_BITS = other._USI_BITS;
_booArr = new usi[other._booArrLen];
for (int i = 0; i < _booArrLen; ++i)
_booArr[i] = other._booArr[i];
_booArrLen = other._booArrLen;
_numBoos = other.numBoos;
}
编译器说:
错误:分配只读变量“BitPack::_USI_BITS”
请摒弃我愚蠢的做法。