I’m having an issue with two of my functions. I have an operator = method as well as an add method. They work fine on their own, as in I can only use one or the other during one compile. For example I need to comment out the add function in order for the operator = method to work and vice versa. The errors I’m getting 10 no match for 'operator=' in 'c = (&a)->HUGE_INT::add(((HUGE_INT&)(&b)))'
HUGE_INT HUGE_INT::operator=(HUGE_INT &orig)
{
//code
return *this;
}
HUGE_INT HUGE_INT::add(HUGE_INT &a)
{
//code
return object;
}
//client
HUGE_INT a(9999999),b(1111),c,d;
c = a.add(b);
d = a;
The problem that you are having is that you are returning by value from
add, and taking the argument tooperator=by non-const reference.The temporary object returned from
addis an rvalue, and so it cannot be bound to a non-const reference.Unless you are doing something very strange, you probably want to change
operator=to take its argument by reference to const:(I also changed it to return by reference, as this is the standard signature for
operator=.)