i am currently thinking about the following problem and cant find any more goolge helps:
i need to demonstrate that functions returning primitive types return rvalues and functions returning objects return lvalues. easy enough with an int and a string object. the part i am stuck on is: how can i change the lvalue i get from a function, say a string, to a rvalue. already in the return type. such that something like the stupid code:
lvalFunc() = "Hello World\n";
does not compile anymore. i can clearly change the return type to a const, but that simply prevents the returned string from being changed and does not make it an lvalue, right?!
I d be greatful for any ideas (:
i need to demonstrate that functions returning primitive types return rvalues and functions returning objects return lvalues
This can't be demonstrated because this is false: value category of a function call expression is not related to whether the return type is a class type or a scalar:
C++ allows member functions (const and non-const) to be called on rvalues. Member functions can make changes to the object. That is exactly what happens here because operator= is a member function.
any other operators that i can use on strings that require an lvalue?
It's tricky because lvalue-to-rvalue conversion is implicit, so if an operator accepts rvalue arguments, it will accept lvalue arguments as well. With sufficient C++11 support, you could write a little tester class, but I can't think of another operator.