Despite the nice answer of @TartanLlama, this is another way one can use decltype
to name actually the given type:
int f() { return 42; }
void g() {
// Give the type a name...
using my_type = decltype(f());
// ... then use it as already showed up
my_type var_a = f();
my_type var_b = var_a;
const my_type &var_c = var_b;
}
int main() { g(); }
Maybe it's worth to mention it for the sake of completeness.
I'm not looking for credits for it's almost the same of the above mentioned answer, but I find it more readable.