std::vector<float> someOp(void)
{
using namespace std;
vector<float> results;
// some operations done to results
return results;
}
int main(void)
{
using namespace std;
vector<float> &results = someOp();
}
Does the vector returned by someOp exist in the someOp() stack space or in the main() stack space?
I’m inclined to believe that it doesn’t get copied/moved to the main() stack space since the results vector has the same address inside of both methods.
Neither, that’s not valid C++ (and doesn’t get compiled by g++).
It seems you’re trying to store a reference to the returned
results, but that’s impossible as the returnedresultsexists in the stack frame ofsomeOp, and, while it will still be there just aftersomeOp()returns, will get overwritten at some point in the future.