I have the following example:
struct A
{
...
};
a function returning A by value
A getFoo()
{
A a;
...
return a;
}
The caller only needs to read that output data.
const A& a = getFoo();
Is it a bad approach ? Should it be ?
const A a = getFoo();
My only concern is about scope. I don't care about modifications, I only need to read. I only care about avoid creating unnecessary copies and not ending with dangling references.