返回类型扣除 [英] Return type deduction

查看:130
本文介绍了返回类型扣除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

忽略C ++中的返回类型11

++ 11 lambda可以推断它们的返回类型,如果主体只包含一个return语句。要移除此限制,提案是作品

In C++11 lambda can deduce their return type if the body consists of only a return statement. A proposal is the works to remove this restriction, and apparently it's already working in GCC.

有一个原因,这不能扩展到所有 auto 返回函数?

已经提出了此扩展程序?

Is there a reason this couldn't be extended to all auto returning functions?
Has this extension already been proposed?

推荐答案


有一个原因,这不能扩展到所有自动返回函数?

Is there a reason this couldn't be extended to all auto returning functions?

好吧,有一个事实,除非函数在那里定义(不只是声明)。

Well, there's the fact that it wouldn't be possible unless the function was defined right there (not just a declaration). You'd lose the ability to forward declare such functions.

此外,函数不返回 auto 。在函数定义前面的 auto 是一个纯语法的东西,允许尾随返回类型。最后指定返回类型的唯一原因是它可以引用函数的参数(对于模板和 decltype 工作,通常)。函数仍然返回一个特定的值。

Also, functions don't return auto. The auto in front of a function definition is a purely syntactic thing to allow for trailing return types. And the only reason the return type is specified last is so that it can refer to the function's arguments (for template and decltype work, usually). The functions still do return a specific value.

这篇关于返回类型扣除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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