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

谁说胖子不能爱 提交于 2019-12-01 16:44:36

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); }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!