Here it means the same thing: when the function returns a value, it will be the actual object we return, not a copy (normally, returning a value does make a copy).Likewise, we use it means that the two strings are literally the same object, because they have the same address.The problem here is that if you’re trying to transactionize the assignment, so that either all of it happens or none of it happens, this breaks that.
operator can be defined, and then it will be used instead when the compiler encounters a typecast.
The reverse is not true: In a regular assignment, the compiler will not consider explicit assignment operators.
One I heard about almost instantly from several people (and which I’m really glad I heard about before delivering a talk on this subject at C World) was a rather serious mistake.
When I first did this article, I had the big "right answer" like this: This was wrong, and it was caught in the review process.
Like most other operators in C , it can be overloaded.
The copy assignment operator, often just called the "assignment operator", is a special case of assignment operator where the source (right-hand side) and destination (left-hand side) are of the same class type.The compiler will consider all overloaded assignment operators till it finds one that matches the types of the left hand and right hand expressions.If no such operator is found, a ’type mismatch’ error is given.The assignment operator defines the action of a assignent of one type of variable to another.The result type must match the type of the variable at the left of the assignment statement, the single parameter to the assignment operator must have the same type as the expression at the right of the assignment operator.This is consistent with the behavior of assignment operator for built-in types (returning the assigned value) and allows for using the operator invocation as an expression, for instance in control statements or in chained assignment.Also, the C Standard Library requires this behavior for some user-supplied types.By the way, I’ve also had several people question my assumption that the delete operations won’t throw exceptions.Technically they’re right, but I’d strongly counsel against letting this happen.One interesting consequence of this is that you can imagine a class with a fairly deep inheritance chain where every class up the chain has other objects it owns.You’d call an assignment operator low in the chain, it’d create the objects it needs, then it’d call its parent, which would create the objects it needs and call its parent, and so on up the chain.