If you use popular compilers (gcc, Visual Studio), you usually do not need to specify the type of the return value, if the compiler can determine it unambiguously - as in your example.
The following example shows lambda, which requires explicit return type information:
auto lambda = [](bool b) -> float { if (b) return 5.0f; else return 6.0; };
I asked Bjarn Straustrup about this, his comment:
I do not know if C++11 allows the deduction of the return type is there are several return statements with identical return type. If not, that's planned for C++14.
Spook Feb 06 '13 at 20:41 2013-02-06 20:41
source share