c++中的默认参数

Default parameter in C++

本文关键字:参数 默认 c++      更新时间:2023-10-16

使用默认参数时,我设置

void method1(float v, float w =1.0)
在定义中使用像 这样的注释是个好习惯吗?
void class::method1(float v, float w /*=1/0*/)

我更喜欢这样的氧兼容文档:

/**
 * Description of the behavior/purpose of your method
 * 
 * @param v The float 'v' (whatever this means)
 * @param w Optional float 'w' (whatever this means), default value is 1.0.
 */
void method1(float v, float w =1.0);

通常我不会在实现特定块中添加额外的注释,

智能在大多数IDE将工作,如果不是你可以保留评论。我不认为这有什么害处。