June 2025
Intermediate to advanced
1093 pages
33h 24m
English
There is another way to write the function header with auto and ->, which is at least equivalent, if not better:
auto FunctionName(ParameterType ParameterName,…)-> ReturnType
For Listing 7.2, it would look like this:
auto func() -> int;auto func() -> std::string;auto func() -> void;auto func() -> std::pair<int,std::string>;auto func() -> vector<int>;auto func() -> vector<int>&;auto func() -> const vector<int>&;
Listing 7.11 Alternative syntax for function declarations with trailing return type.
The advantage is that you can recognize the function name better when the return type becomes more complex. This can happen with templates that have multiple type arguments. For programmers who ...
Read now
Unlock full access