Without the error message, I'm not exactly sure what the compiler might be complaining about, but I can explain the reason logically:
In the line:
bar(foo());
The return value of foo() is a temporary A; it is created by the call to foo(), and then destructed as soon as bar() returns. Performing a non-const operation (i.e. an operation that changes the temporary A) doesn't make sense, as the object A is destructed right afterwards.
Looking a little more, this is a virtual dup of this question:
http://stackoverflow.com/questions/1565600/non-const-reference-to-temporary-object
which has an excellent answer.