Can the return type of a function be obtained in a simple way within the function?
For example, given:
template <typename P>
static inline auto foo(P p) -> typename std::remove_reference<decltype(*p)>::type {
typename std::remove_reference<decltype(*p)>::type f{}; // <-- here
...
}
In C++11 can I refer to the big nasty return type of foo
, within foo
itself, without repeating it, at the line marked // <-- here
?
function myFunction(a: number, b: number): void { console. log(a); console. log(b); } // 👇️ type T = void type T = ReturnType<typeof myFunction>; If the function might return values of multiple types, its return type will be a union type.
A function is an instance of the Object type. You can store the function in a variable. You can pass the function as a parameter to another function. You can return the function from a function.
Explanation: True, The default return type for a function is int.
A function that returns a value is called a value-returning function. A function is value-returning if the return type is anything other than void . A value-returning function must return a value of that type (using a return statement), otherwise undefined behavior will result.
Call the function with a decltype
.
decltype(foo(p)) f{};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With