在C ++中将默认参数值放在哪里? [英] Where to put default parameter value in C++?

查看:129
本文介绍了在C ++中将默认参数值放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认参数值的位置是什么?

解决方案

默认参数值必须出现在声明上,因为这是在函数定义或声明,

编辑:正如其他人所指出的,您可以 定义,但我建议写所有的代码,如果这不是真的。


What's the place for the default parameter value? Just in function definition, or declaration, or both places?

解决方案

Default parameter values must appear on the declaration, since that is the only thing that the caller sees.

EDIT: As others point out, you can have the argument on the definition, but I would advise writing all code as if that wasn't true.

这篇关于在C ++中将默认参数值放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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