This is what my Book Says:
//start
Alternative Function Syntax
The C++ 11 introduces an alternative syntax for writing the function header. Here’s an example of
the power() function that you saw earlier defi ned using the alternative syntax:
1 2 3 4 5 6 7
|
auto power(double x, int n)-> double // Function header
{ // Function body starts here...
double result(1.0); // Result stored here
for(int i = 1; i <= n; i++)
result *= x;
return result;
} // ...and ends here
|
This will work in exactly the same way as the previous version of the function. The return type of the function appears following the -> in the header. This is referred to as a trailing return type. The auto keyword at the beginning indicates to the compiler that the return type is determined later.
So why was it necessary to introduce the alternative syntax? Isn’t the old syntax good enough? The answer is no. In the next chapter you’ll learn about function templates, where situations can arise when you need to allow for the return type from a function to vary depending on the result of executing the body of the function. You can specify that with the old syntax. The alternative
function syntax does allow you to do that, as you’ll see in Chapter 6.
//end
It clearly says that the old syntax allows you to do that so why do you need the new alternative syntax o.O. Is it just me or is this a mistake/typo?
PDF available here:
http://it-ebooks.info/read/975/ Page 236, it may take a couple minutes to load. I even checked it on google books and the same "typo" is there although I cant seem to let google let me get on the same page or preview it till there again for some reason.
Thank You and I would appreciate some help please.