通过引用传递向量 [英] Passing vectors by reference
问题描述
如果我有一个类中的对象的向量,我想在另一个类中改变,我会尝试并通过引用传递所有的信息。
If I have a vector of objects in one class which I want to change in another, I would try and pass all the information by reference.
我需要通过参考吗?向量?对象?两个?
What exactly do I need to pass by reference though? The vector? The objects? Both?
我要求的基本上是:这些之间有什么区别?
Essentially what I'm asking is: What is the difference between these?
vector&<object> blah; // A reference to a vector of objects?
vector<object&> blah; // A vector of references to objects?
vector&<object&> blah; // A reference to a vector of references to objects???
我实际上不确定如何引用数组类容器的工作原理。这些是合法的吗?
I'm not actually sure how referencing of array like containers work. Are these legal?
推荐答案
vector&< object>
语法错误。 向量< object&>
无效,因为向量的值类型必须可分配。 矢量&< object&> blah
是语法错误。
vector&<object>
is a syntax error. vector<object&>
is invalid, because a vector's value type must be assignable. vector&<object&> blah
is a syntax error.
对向量的引用是向量< T>&
。
这篇关于通过引用传递向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!