应该避免使用尾部返回类型吗? [英] Should main with trailing return type be avoided?

查看:109
本文介绍了应该避免使用尾部返回类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码示例中, main 函数使用C ++ 11结尾返回类型符号表示:

  auto main() - > int {
// ...
return 0;
}

问题: b

是否应该避免使用尾随返回类型的 main ,并且应该优先使用古典符号?

解决方案

这完全有效,工作正常。



值得关注的是它是新的。



但它的工作原理,所以随意写你的这种方式,如果你喜欢它。


In the code example below the main function is written with the C++11 trailing return type notation:

auto main() -> int {
  //...
  return 0;
}

Question:

Are there any reasons that main with trailing return type should be avoided and the classical notation should be preferred?

解决方案

It's perfectly valid and works just fine.

The only issue to concern is that it is new. It may confuse or surprise readers of your code who are only familiar with C++98.

But it works, so feel free to write your main this way if you feel like it.

这篇关于应该避免使用尾部返回类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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