I'm trying to implement the following operator:
void operator=(const mpz_t &a, const myDatatype &b);
I need this operator to convert a variable from myDatatype to mpz_t from GMP (mpz_t x = y, where y has the datatype myDatatype). In the header file, I declare this function outside of the class. However, I have some other '=' operator declarations inside, since I want to convert variables of other datatypes to myDatatype.
class myDatatype {
public:
//variable, constructors and destructor declaration
...
void operator=(const mpz_t &a);
void operator=(const myDatatype &a);
//some methods
};
void operator=(const mpz_t &a, const myDatatype &b);
The error I get is:
error: ‘void operator=(const __mpz_struct (&)[1], const myDatatype&)’ must be a nonstatic member function
void operator=(const mpz_t &a, const myDatatype &b);
I read that "A binary operator shall be implemented either by a non-static member function with one parameter or by a non-member function with two parameters", which is what I am doing, I think. How can I solve this?