class test{
...
public:
...
test operator+(const test &a)const;//#1
const test & operator+=(const test &a);//#2
std::ostream & operator<<(std::ostream &os, const test &a);//#3
}
#1, if I have a statement testa = testa + testb + testc + testd;, how would I know the sequence is left-to-right, or it's right-to-left?
testa.operator+(testb.operator+(testc.operator+(testd)));//right-to-left
((testa.operator+(testb)).operator+(testc)).operator+(testd);//left-to-right
Both works.
#2, similar to #1
#3, Due to the return type is on the left side of the argument list, the statement seems can only to the left-to-right version. If the return type is const test &a, it can be cout<<(fout<<(cout<<testd)), but it's obviously meaningless here.
The choice between parsing a + b + c as (a + b) + c or as a + (b + c) is decided by the C++ language grammar, and is often explained as "associativity of operators"