Why does the code below compile and run w/o error? Isn't the return value of goobar() a temporary object? Why would the compiler C++20 permit a reference to it?
#include <iostream>
using namespace std;
struct cfoobar
{
const int& x;
cfoobar(const int&y) : x(y) { }
};
int goobar(int x)
{
int y = x;
return y;
}
int main()
{
cfoobar a(goobar(159));
cout << a.x<< endl;
}
The output is 159 just as I would not expect. Thank you kindly - cheerio