6.3Return Types and the return Statement &6.5Overloaded functions

  • Hence, the form of a function that returns a pointer to an array is: 

    Type (*function(parameter_list))[dimension]

    C++11:

    trailing return type:

    auto func(int) -> int(*) [10];

    Using decltype:

    int odd[] = {1,3,5,7,9};
    int even[] = {0,2,4,6,8};
    // 
    returns a pointer to an array of five int elements

    decltype(odd) *arrPtr(int i) 


  •  A parameter that has a top-level const is indistinguishable from one without a top-level const

    Record lookup(Phone);
    Record lookup(const Phone); // redeclares Record lookup(Phone)
    Record lookup(Phone*);
    Record lookup(Phone* const); // redeclares Record lookup(Phone*)

    In these declarations, the second declaration declares the same function as the first.

    On the other hand, we can overload based on whether the parameter is a reference(or pointer) to the const or nonconst version of a given type; such consts are low-level: 

    // functions taking const and nonconst references or pointers have different parameters
    // declarations for four independent, overloaded functions
    Record lookup(Account&); // function that takes a reference to Account
    Record lookup(const Account&); // new function that takes a const reference
    Record lookup(Account*); // new function, takes a pointer to Account
    Record lookup(const Account*); // new function, takes a pointer to const
    


  • We may define defaults for one ormore parameters. However, if a parameter has a default argument, all the parametersthat follow it must also have default arguments. 


  • The default arguments are used for thetrailing (right-most) arguments of a call. 

    Part of the work of designing a function with default arguments is ordering theparameters so that those least likely to use a default value appear first and thosemost likely to use a default appear last. 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值