So, I have a vector that is either full of integers. Lets call this vector Vect. I have my code in main.cpp and VectorList.h, and cannot change that fact. In VectorList.h one of my functions is:
void insertAtFront( const int & );
Now where I’m encountering trouble, I know I can add the integer to the start of the vector using std::vector.insert() function. But, insertAtFront does not have access to the vector itself, however, this is the only data member in VectorList.h:
vector< int > *vList
So, my question is how can I add a value to the beginning of a vector Vect using only this pointer *vList?
My first idea was something like this:
&vList.insert(&vList.begin(), 1, &value) // with value being the input integer
but that doesn’t work :/ any suggestions?
If you have a pointer to a vector, then you would need to use the
->operator. Using the&operator in this case will give you the address of the return value ofvList.begin(). That won’t work too well, considering you can’t use the.operator on a pointer to begin with. Instead, you need to dereference the pointer. Try:vList->insert(vList->begin(), value);Edit: I’m not sure why you would need the middle argument in this case. You should be fine omitting it. I have done so in the line of code I wrote here.