【发布时间】:2020-06-10 23:18:42
【问题描述】:
如果在函数中,参数按一定顺序列出
int foo( size_t bar, int baz )
{
/*
Some very important code here
*/
return zap;
}
如果我这样称呼它有关系吗:
size_t size = 16;
int op = 19;
foo( size, op );
或者
foo( op, size);
【问题讨论】:
-
这取决于,对于可交换函数
constexpr int add(int a, int b) {return a+b;} static_assert(add(42, 58) == add(58, 42));它是相同的,但对于非可交换函数constexpr int sum(int a, int b) {return a-b;} static_assert(sum(42, 58) == sum(58, 42));。不一样