J
Jacopo
Hi, I'm running this code:
class C {
private:
int d;
public:
C(string s=""): d(s.size()) {}
explicit C(int n): d(n) { cout<<"*1*"; } // 1
operator int() { cout<<"*2*";return d; } // 2
C operator+(C x) { cout<<"*3*";return C(d+x.d); } // 3
};
main() {
C a, b("pippo"), c(3); cout<<std::endl;
cout << a << ' ' << 1+b << ' ' << c+4 << ' ' << c+b;
}
It prints:
*1*
*3**1**2**2**2**2*0 6 7 8
Look at the second line: ok for the last four numbers, but output
produced from function calls seems to start from the end (c+b
evaluation), in reverse order.
I'm not sure why, so could someone clarify this behaviour ?
Thanks.
class C {
private:
int d;
public:
C(string s=""): d(s.size()) {}
explicit C(int n): d(n) { cout<<"*1*"; } // 1
operator int() { cout<<"*2*";return d; } // 2
C operator+(C x) { cout<<"*3*";return C(d+x.d); } // 3
};
main() {
C a, b("pippo"), c(3); cout<<std::endl;
cout << a << ' ' << 1+b << ' ' << c+4 << ' ' << c+b;
}
It prints:
*1*
*3**1**2**2**2**2*0 6 7 8
Look at the second line: ok for the last four numbers, but output
produced from function calls seems to start from the end (c+b
evaluation), in reverse order.
I'm not sure why, so could someone clarify this behaviour ?
Thanks.