Automatic Return Type
In this lesson, we'll look at the technique that deduces return type automatically.
We'll cover the following...
Automatic Return Type
A function template is automatically able to deduce their return type.
template <typename T1, typename T2>
auto add(T1 fir, T2 sec) -> decltype( fir + sec ) {
return fir + sec;
}
The automatic return type deduction is typically used for function templates but can also be applied to non-template functions.
Rules:
-
auto
: introduces the syntax for the delayed return ...