“与"运算符是什么意思?在一个类和一个变量之间是什么意思? [英] What does "ampersand operator" mean between a class and a variable?
问题描述
我看到了下面的代码,非常困惑:
I saw the following code in plumed and am quite confused:
void ActionAtomistic::makeWhole() {
for(unsigned j=0; j<positions.size()-1; ++j) {
const Vector & first (positions[j]);
Vector & second (positions[j+1]);
second=first+pbcDistance(first,second);
}
}
谁能告诉我什么是&"用于这里吗?我用Google搜索类和变量之间的C ++连字符",但没有找到答案.
Could anyone tell me what "&" is used for here? I googled "c++ ampersand between class and variable" but did not find the answer.
已更新:我知道引用是什么,但认为Vector和&"之间不应有任何空格.谢谢大家的澄清.
Updated: I know what reference is but thought there should not be any space between Vector and "&". Thank you guys for clarifying that.
推荐答案
这意味着 first
是引用(在本例中为 const 代码>引用)指向类型为
Vector
的对象,而不是类型为 Vector
的对象.
This means that first
is a reference (in this case, a const
reference) to an object of type Vector
, rather than an object of type Vector
.
在此处中了解更多有关引用的信息.
Read more about references here.
这篇关于“与"运算符是什么意思?在一个类和一个变量之间是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!