package GMP and overload operator problem:

Creatxr creatxr at gmail.com
Wed Sep 21 23:58:47 CEST 2011


Hi,

i try to pakage GMP and overload operator as below:

class TGMP {
public:
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|


More information about the gmp-discuss mailing list