Yes, it does point to the very vector myVec in your MyClass instance. See the following sample code:
#include <cstdio>
#include <vector>
class MyClass {
std::vector<int> myVec;
public:
MyClass() {}
~MyClass() {}
std::vector<int>& getVector()
{
return myVec;
}
void printVector() const
{
for(std::vector<int>::const_iterator it = myVec.begin(); it != myVec.end(); ++it)
{
printf("%d ", *it);
}
printf("\n");
}
};
int main(int, char**)
{
MyClass item;
std::vector<int>* vec = &(item.getVector());
vec->push_back(1);
item.printVector();
return 0;
}
Running this program will output:
$ ./a.out
1
So you can see that calling getVector()
returns a reference to myVec
from the MyClass instance, since we add a new item to the vector (vec->push_back(1)
) via the vec
pointer then print the MyClass instance's vector, and it shows that the item we added is there in myVec
.