将引用参数传递给值参数

passing reference argument to value argument

忽略可能在下面的 C++ 代码中完成的任何编译器优化,

void f(int n) {
    n += 1;
}

void g(int &n) {
    f(n);
}

相当于

void f(int n) {
    n += 1;
}

void g(int *n) {
    f(*n);
}

?

所以当使用引用参数时,仍然可以在不那么明显可见的地方创建值副本?

编辑 我在问是否可以使用引用参数制作实际值副本。在第二种情况下使用指针时,我显式取消引用指针以按值传递,但是使用引用参数有时会隐式取消引用吗?是我的问题。

I am asking about whether actual value copies can be made with reference arguments.

当然可以。它是参考的事实是无关紧要的。您可以像对待它引用的对象一样对待它。

When using pointers as in the second case, I explicitly dereference the pointer to pass by value, but will using reference arguments sometimes do the dereferencing implicitly?

您将引用视为某种隐藏指针。该术语在这里并没有真正的帮助。 "Dereferencing" 是您对指针而不是引用所做的事情。事实上,标准已更改为使用 "perform indirection" 而不是 "dereference" 来帮助澄清这一点。关键是,引用没有被取消引用,因为这不会发生 - 您只是复制被引用的对象。