For a long time I thought that the ternary operator always returns an rvalue. But to my surprise it doesn't. In the following code I don't see the difference between the return value of foo and the return value of the ternary operator.
I've read that lvalues are "things with a defined storage location".And also that literals and temporaries variables are not lvalues, but no reason is given for this statement.
The program still prints a word copying which indicates that the copy constructor is activated. Where is the constructor called then ? Why the function does not return a reference of o1 so that modifying the value of res will also changing the value of o1 ?
Suppose I have a chunk of dynamically allocated data:I wish to use the data pointed at by foo as a special type, type_t. But I want to do this later, and not during allocation. In order to give the allocated data an effective type, I can therefore do something like: