c++ - 删除函数定义(编码标准)中未使用的参数名称。

标签 c++

Herb Suttter C++ 编码标准说,删除函数中未使用的参数名称以编写零警告程序是一种很好的做法。

例子:

int increment(int number, int power=0){
   return number++;
}

应该是

int increment(int number, int /*power*/=0){
   return number++;
}

如果 power 参数存在“未使用的变量警告”。 这适用于程序(没有编译错误),所以新的函数定义将是

int increment(int number, int =0)

那么 int=0 对编译器意味着什么?

最佳答案

默认值为 0 的未命名形式参数。

第一种情况(最流行)是在function-declaration 中的用法,比如

int increment(int, int = 0);

并且在定义参数时会被命名。

int increment(int number, int power)
{
   //
}

第二种情况是用于调试目的,或用于某些尚未实现的功能,或用于虚拟函数。

关于c++ - 删除函数定义(编码标准)中未使用的参数名称。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15739252/

相关文章:

c++ - 调用内存对象的虚函数

c++ - 如何从程序的开头开始

c++ - 将具有结构初始化和赋值的 C 代码移至 C++ 编译器

c++ - 列出运行时使用的 opengl 扩展

C++11 继承构造函数和访问修饰符

c++ - Meyers 提出的 MCU 寄存器抽象的新布局

c++ - 几个线程 : catching the moment when they all finish work

python - Jupyter Notebook 不显示 C++ 输出 (cout)

c++ - 从 C++ libneo4j_client 中的参数化语句中获取结果

c++ - 重载 << 运算符时访问私有(private)类成员的问题