cout<<"f1 count is "
<<f1.getcount()<<endl
<<"f2 count is "
<<f2.getcount()<<endl
<<"f3 count is "
<<f3.getcount()<<endl
<<"f4 count is "
<<f4.getcount()<<endl;
The behavior of this piece of code is undefined.
Another example:
1 2
int x = 0;
std::cout << x++ << ' ' << x++ << std::endl;
What do you think the output will be? Regardless of what answer you gave, it's wrong. With a few exceptions, the language doesn't specify the order of evaluation of expressions, so using multiple operations with side effects (e.g. increments, assignments, function calls) on a single object give undefined behavior.
Maybe you're right, helios, I tried your example, the output was arbitrary, but it's not the case in my example, it's the accurate output but reversed.
Yes, again: it's undefined. You're seeing the effects of undefined behavior. "Undefined" doesn't mean "random" or "nonsensical", it means that any behavior is permissible.
Yeah yeah ... I got you right now, actually I exprienced a combination of your example and it shown a very wierd results, some of it was wrong but also have some logic, thanks a lot for your great help!