In C++, this code does not compile:
double* value() {
return nullptr;
}
double*& function() {
return value();
}
Error: Non-const lvalue reference to type 'double *' cannot bind to a temporary of type 'double *'
However, this code does compile without errors:
double* value() {
return nullptr;
}
double*& function() {
double* valueVar = value();
return valueVar;
}
Can someone explain to me why? I would've thought they did exactly the same thing, to me the second code just looks redundant.