“与"运算符是什么意思?在一个类和一个变量之间是什么意思? [英] What does "ampersand operator" mean between a class and a variable?

查看:49
本文介绍了“与"运算符是什么意思?在一个类和一个变量之间是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了下面的代码,非常困惑:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆