The value of A T&
not a copy, it is a reference .
Links are very similar to pointers: they are lightweight and can be used to modify the underlying object. Only you use them with the same syntax as direct objects (with dots instead of arrows), and some other differences that you can check in the article.
To edit an object inside Vector, you can use, for example, vector[i].action();
. This will call the action () method from the object inside the vector, not from the copy. You can also pass a link to other functions (provided that they accept supporting arguments), and they will still point to the same object.
You can also get the address of an object from a link: Object* pObject = & vector[i];
and use it like any pointer.
If you really need pointers to objects, you can also use a vector of pointers: QVector<Object*> vector;
However, this requires you to create / destroy processing, which you do not need with Vector objects.
Now, if you want a pointer to the vector itself, just do QVector<Object> *pVector = &vector;
source share