Firas 于 2014.10.12 23:59 提问

77: error: expected unqualified-id before '^' token
``````#define TO_SIGNED(x)    ((signed)(x))
class BigInteger{
protected:
unsigned* array;

BigInteger(unsigned*const theArray){
array = theArray;
}

inline unsigned* getArray(){
if(this == BigIntegerNull)
#ifdef _EXCEPTION_H_
throw NullPointerException();
#else
return NullArray;
#endif
return array;
}

BigInteger expand(unsigned newSize, bool extendSign){
if(getArray() == NullArray){
BigInteger n(NullArray);
return n;
}
if(newSize <= array[0]) return *(new BigInteger(*this));
BigInteger nbi(new unsigned[newSize+1]);
register unsigned i;
for(i = 0; i <= array[0]; i++) nbi.array[i] = array[i];
if(extendSign && TO_SIGNED(array[array[0]]) < 0){
for(; i <= newSize; i++) nbi.array[i] = -1;
}else{
for(; i <= newSize; i++) nbi.array[i] = 0;
}
return nbi;
}
public:

static BigInteger*const BigIntegerNull;
static unsigned*const NullArray;

BigInteger(const BigInteger& origin){
#ifdef _EXCEPTION_H_
if(origin.getArray() == NullArray)
throw NullPointerException();
#endif
register unsigned size = origin.array[0]+1;
array = new unsigned[size];
do{
--size;
array[size] = origin.array[size];
}while(size > 0);
}

BigInteger _xor(BigInteger bi, bool extendSign){
if(getArray() == NullArray || bi.getArray() == NullArray){
BigInteger n(NullArray);
return n;
}
register unsigned i;

if(array[0] <= bi.array[0]){
for(i = array[0]; i > 0; i--) array[i] &= bi.array[i];
}else{
for(i = 1; i <= bi.array[0]; i++){
array[i] ^= bi.array[i];
}
if(extendSign && TO_SIGNED(bi.array[bi.array[0]]) < 0){
for(; i <= array[0]; i++){
array[i] = -1;  // or -1
}
}
}

return *this;
}

BigInteger xor(BigInteger bi, bool extendSign){    // 编译器指示错误的行
BigInteger n(NullArray);
if(getArray() == NullArray || bi.getArray() == NullArray){
return n;
}
register unsigned i;
if(array[0] <= bi.array[0]){
n = this->expand(bi.array[0], extendSign);
for(i = array[0]; i > 0; i--){
n.array[i] ^= bi.array[i];
}
if(extendSign && TO_SIGNED(bi.array[bi.array[0]]) < 0){
for(; i <= bi.array[0]; i++){
n.array[i] = ~bi.array[i];  // xor -1
}
}else{
for(; i <= bi.array[0]; i++){
n.array[i] = bi.array[i];   // xor 0
}
}
}else{
n = *(new BigInteger(*this));
for(i = 1; i <= bi.array[0]; i++){
n.array[i] ^= bi.array[i];
}
if(extendSign && TO_SIGNED(bi.array[bi.array[0]]) < 0){
for(; i <= array[0]; i++){
n.array[i] = ~array[i]; // xor -1
}
}
}
return n;
}
};
BigInteger*const BigInteger::BigIntegerNull = reinterpret_cast<BigInteger*>(0);
unsigned*const BigInteger::NullArray = reinterpret_cast<unsigned*>(0);
``````