有人封裝過GMP庫嗎?这样的情况該怎麽办。謝謝
class TGMP {
public:
const mpz_t& getValue(); // return this->value; // 由於 mpz_t 類型是一種數組類型,c++中不能返回數組類型,
//所以只好用 const 限制,防止被人通過 a = b.getValue(); 方式获得引用,从而从外部更改類内部的私有变量
TGMP(); //------init value field here
virtual ~TGMP(); //------destory value field here
TGMP& operator = (const TGMP&); // this operator is passed
TGMP operator + (const TGMP&); // this operator is passed
......
bool operator == (const TGMP&); // here is error ??? it
cannot set to "const"
protect:
private:
mpz_t value;
}
===================
implement:
bool TGMP::operator == (const TGMP& o) {
if (mpz_cmp(value, o.getValue())==0) { //--------------error
return true;
} else {
return false;
}
}
=========================
TGMP.cpp|94|error: passing ‘const TGMP’ as ‘this’ argument of ‘const
__mpz_struct (& TGMP::getValue())[1]’ discards qualifiers|