Код: Выделить всё
struct Foo
{
operator int&() { return bar; }
int bar{42};
};
void fuz()
{
Foo foo;
auto& baz{static_cast(foo)}; // Works
const auto& biz{static_cast(foo)}; // Works
auto& buz{static_cast(foo)}; //
Подробнее здесь: [url]https://stackoverflow.com/questions/79812164/correct-way-to-invoke-the-conversion-operator-returning-a-reference[/url]
Мобильная версия