What is the meaning of auto when using C++ trailing return type?

后端 未结 2 1554
走了就别回头了
走了就别回头了 2020-12-03 11:16

Instead of usual

void foo (void ) {
    cout << \"Meaning of life: \" << 42 << endl;
}

C++11 allows is an al

2条回答
  •  情话喂你
    2020-12-03 11:59

    In general, the new keyword auto in 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.

提交回复
热议问题