I want to overload the operator = and I have the following operator-function
int IntegerClass::operator=(IntegerClass integer) {
return integer.number;
}
This should be correct?
In another class I want to assign the objects private member (int) to another int i.e.
int x = integerClass;
but when I compile I get the following error
error: cannot convert 'std::IntegerClass' to 'int' in initialization
What is wrong with my implementation of operator-overloading and how should the function look like?
int x = integerClassdoesn't invoke any operators (it is initialization and not assignment), and especially notIntegerClass::operator=. If any, you could try implementingIntegerClass::operator int()instead to support implicit conversion toint. - user529758std::IntegerClass? The standard library doesn't have such a class AFAIK. You added your class tostd? That's bad. - leemes