Ask Your Question
0

How to properly transmit a `decltype(auto)` variable from a function?

asked 2023-04-03 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-07-03 18:00:00 +0000

woof gravatar image

To properly transmit a decltype(auto) variable from a function, you can use either auto or decltype to declare the variable in the receiving function.

For example, in the sending function, you can have:

decltype(auto) var = some_function();
return var;

And in the receiving function, you can have:

auto var2 = sending_function();

or

decltype(var) var2 = sending_function();

Either way, the decltype(auto) variable will be correctly transmitted and stored in the receiving function as auto or with the same type as the original variable using decltype.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-04-03 11:00:00 +0000

Seen: 8 times

Last updated: Jul 03 '22