reference to std::vector vs pointer to array of vectors.
Posted: Sat Oct 17, 2009 9:40 pm
float sum(const vector<float>& x); // prototype
float sum(const vector<float> * x); // other prototype
Ok, so I am having trouble seeing the difference between these two. Probably because I have some deep seeded misconception about arrays and pointers.
I understand why the first one works, your passing a reference to a vector. Ok. In the second one, I get confused. If you use the second prototype, and inside the sum function you say x[0] you get a pointer to the vector array as a whole, and not the 0th (first) element in the array. If you do x[0][0] you get the first element in the vector.
Why in the second prototype do you get a pointer to an array of vectors instead of a pointer to the one single vector?
float sum(const vector<float> * x); // other prototype
Ok, so I am having trouble seeing the difference between these two. Probably because I have some deep seeded misconception about arrays and pointers.
I understand why the first one works, your passing a reference to a vector. Ok. In the second one, I get confused. If you use the second prototype, and inside the sum function you say x[0] you get a pointer to the vector array as a whole, and not the 0th (first) element in the array. If you do x[0][0] you get the first element in the vector.
Why in the second prototype do you get a pointer to an array of vectors instead of a pointer to the one single vector?