Take this example code:
int a = 10;
int b = 20;
int c = 30;
int & foo1() {
qDebug() << "foo1" << endl;
return a;
}
int & foo2() {
qDebug() << "foo2" << endl;
return b;
}
int & foo3() {
qDebug() << "foo3" << endl;
return c;
}
int main(void)
{
foo1() = foo2() = foo3() = 7;
}
Since assignment goes right to left, I expected to see foo3
first and foo1
last, but it is the opposite.
Are the rules for such scenarios concretely defined and how? Also, does the compiler differentiate between assignment and other operators and how would that be possible if you are using the =
operator in a different context than initialization? Maybe chain assignment is treated differently from other chaining?