I have a class and want to overload the "+" and "=" operator for this class. so i implement operator+ as a friend function and operator= as a member funcion...
If the argument type of operator= defined as reference, then the following line can't be run because the right hand side is a value and don't have any address :
sum = A + B; // sum, A and B are objects of my class
But i want to be able to do such assignments and also want to pass arguments to operator= by reference (because objects of my class are huge). is it possible or i have to pass arguments to operator= by value??
You just need to take in the argument by reference-to-const:
const
references can bind to rvalues, sosum = A + B
is valid.