c++ - 哪个参数应该首先是 `old` 或 `new` ?

标签 c++ naming-conventions

<分区>

我已经创建了函数 replaceElement。我不确定 old 参数应该是第一个还是第二个。在这种情况下,参数顺序的常见方式是什么?

void replaceElement(Element *old, Element *n);

void replaceElement(Element *n, Element *old);

最佳答案

我会选择 void replaceElement(Element *old, Element *n);

这对我来说听起来更好,而且你以后可能想做一个默认参数。在您的案例中,默认值为 new

std::replace 也是这样形成的:

template< class ForwardIterator, class T >
void replace( ForwardIterator first, ForwardIterator last,
              const T& old_value, const T& new_value );

关于c++ - 哪个参数应该首先是 `old` 或 `new` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11591073/

相关文章:

c++ - std::gcd 无法在 g++ 5.4.0 中编译 - 'gcd' 不是 'std' 的成员

java - 当不使用变量时,lambda 表达式中的变量名称约定是什么?

language-agnostic - 百分比、百分比、分数、比例因子的术语?

c++ - Qt C++ MySQL 到 QTableView 多个连接表为空

c++ - 为什么 `true` 和 `false` 都被认为是变量?

C 库命名约定

css - 在 CSS ID 命名约定中可以混合使用下划线和破折号(连字符)吗?

iphone - Objective-C 命名约定——澄清

c++ - C++ 中的声明

C++ recvfrom 不接收所有(二进制)数据