Instead of usual
void foo (void ) {
cout << "Meaning of life: " << 42 << endl;
}
C++11 allows is an alternative, using the Trailing Return
auto bar (void) -> void {
cout << "More meaning: " << 43 << endl;
}
In the latter – what is auto designed to represent?
Another example, consider function
auto func (int i) -> int (*)[10] {
}
Same question, what is the meaning of auto in this example?
In general, the new keyword
autoin C++11 indicates that the type of the expression (in this case the return type of a function) should be inferred from the result of the expression, in this case, what occurs after the->.Without it, the function would have no type (thus not being a function), and the compiler would end up confused.