This is allowed in C ++ 14 (and is called automatic type return), you can enable it in your compiler with std=c++1y now.
You can use the return type if your compiler supports C ++ 11 but not C ++ 14:
auto myfunc(int a) -> int { int b = a; return a; }
source share