I always believed that temporary objects in C++ are automatically considered as const by the compiler. But recently I experienced that the following example of code:
It all depends on the return type of the function.
//Temporary objects: nameless objects that are only usable in current statement
Object function(); //Return a temporary object by value (using copy constructor)
const Object function(); //Return a const temp object by value
//references, return a reference to an object existing somewhere else in memory
Object & function(); //Return an object reference, non-const behaves as any other non-const
const Object & functon(); //Return const obj reference, behaves as any other const