C++11—Trailing Return Types for Functions


C++11 introduces trailing return types for functions. To specify a trailing return type you place the keyword auto before the function name, then follow the function’s parameter list with -> and the return type. For example, to specify a trailing return type for function template maximum (Fig. 6.24), you’d write

template < typename T >auto maximum( T x, T y, T z ) -> T

As you build more complex function templates, there are cases for which only trailing return types are allowed. Such complex function templates are beyond this book’s scope.

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.