码迷,mamicode.com
首页 > 其他好文 > 详细

auto main()-> int的含义是什么?

时间:2019-11-25 18:07:02      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:etc   str   The   selected   UNC   ecif   tle   prim   https   

C++11 introduced a notation for trailing return types: If a function declaration is introduced with auto, the return type will be specified after the parameters and a -> sequence. That is, all that does is to declare main() to return int.

The significance of trailing return types is primarily for function template where it is now possible to use parameters to the function together with decltype() to determine the return type. For example:

template <typename M, typename N>
auto multiply(M const& m, N const& n) -> decltype(m * n);

This declares the function multiply() to return the type produced by m * n. Putting the use of decltype() in front of multiply() would be invalid because m and n are not, yet, declared.

Although it is primarily useful for function template, the same notation can also be used for other function. With C++14 the trailing return type can even be omitted when the function is introduced with auto under some conditions.

 

 

auto main()-> int的含义是什么?

标签:etc   str   The   selected   UNC   ecif   tle   prim   https   

原文地址:https://www.cnblogs.com/Davirain/p/11929218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!