I have difficulties in understanding the sequence of calls in the code below. I was expecting to see the output below
A1B2
While I can
The order of execution of << is well defined but the order of evaluation of sub-expressions is not defined in C++. This article and the C code example illustrates the problem you mentioned.
BA12 and AB12 are both correct. In the following code:
std::cout<< b->fooA() << b->fooB()
1 will appear before 2 but A could appear before or after B since the compiler does not promise whether it will evaluate fooA or fooB first.