使用C ++后缀返回类型时,auto的含义是什么? [英] What is the meaning of auto when using C++ trailing return type?

查看:599
本文介绍了使用C ++后缀返回类型时,auto的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而不是通常

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

C ++ 11 允许是一个替代方法,使用尾随返回

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?

另一个例子,考虑函数

auto func (int i) -> int (*)[10] {

}

问题,在此示例中 auto 的含义是什么?

Same question, what is the meaning of auto in this example?

推荐答案

通常,C ++ 11中的新关键字 auto 表示应该推断表达式的类型(在这种情况下是函数的返回类型)从表达式的结果,在这种情况下,发生在 - > 之后。

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.

这篇关于使用C ++后缀返回类型时,auto的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆