main() {
f5() = X(1); // OK -- non-const return value
f5().modify(); // OK
f7(f5()); // OK
// Causes compile-time errors:
//! f6() = X(1);
//! f6().modify();
//! f7(f6());
}
I dont understand that how can a function act like variable and get assigned the value. For eg. f5() = X(1) in the above code. Is a function used as a variable here?
The function f5 returns a temporary, non-const, copy of an X instance, which may be modified (assigned to). However, this example is only demonstrating that fact--the result after its value is modified is discarded and the temporary instance is destroyed.