Question 1> what does the following code meaning and what the order of assignment is?
ClassName a1, a2, a3;
a1 = a2 = a3;
Does it mean to First assign value of a3 to a2 and then assign ?? to a1.
Question 2> what does the following code meaning?
ClassName a1, a2, a3;
(a1 = a2) = a3;
Question 3>
Given a class as follows:
class A
{
...
}
What operators have to be defined in order to support the following operation?
A a1, a2, a3;
(a1 = a2) = a3;
Question 1
This:
is equivalent to this:
For primitive types, or for PODs, this is equivalent to:
For user-defined types, it’s equivalent to:
If you don’t define your own overloads of
operator=, then this will be the same as for the primitive types.Question 2
This:
only works for user-defined types. It is equivalent to:
If you use the compiler-provided operators, then this is equivalent to:
Question 3
No operators have to be defined, as the compiler provides a copy-assignment operator implementation if you don’t write your own.