Why C++ does not allow function parameters used for default values latter parameters?

后端 未结 1 1745
滥情空心
滥情空心 2021-01-18 04:15

This is a follow-up on this question. The code in the OP question there looked quite reasonable and unambiguous to me. Why does not C++ allow using former parameters to defi

相关标签:
1条回答
  • 2021-01-18 04:47

    For one thing, this would require that a is evaluated before b, but C++ (like C) does not define the order of evaluation for function parameters.

    You can still get the effect you want by adding an overload:

    int foo(int a, int b)
    { /* do something */ }
    
    int foo(int a)
    { return foo(a, a); }
    
    0 讨论(0)
提交回复
热议问题