Например, в C++ я могу достичь этой цели в одной строке (без какой-либо временной переменной) следующим образом:
Код: Выделить всё
#include
struct Temp {
int a;
int b;
};
struct MyTemp {
int a;
int b;
};
struct Temp get_temp(int a, int b) {
struct Temp temp = {
.a = a,
.b = b,
};
return temp;
}
int main() {
struct MyTemp mt = reinterpret_cast(std::move(get_temp(1, 2)));
}
Код: Выделить всё
struct Temp {
int a;
int b;
};
struct MyTemp {
int a;
int b;
};
struct Temp get_temp(int a, int b) {
struct Temp temp = {
.a = a,
.b = b,
};
return temp;
}
int main() {
struct MyTemp mt = *(struct MyTemp *)&get_temp(1, 2);
// error: cannot take the address of an rvalue of type 'struct Temp'
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -an-rvalue