Why dereferencing is not needed in this case?
Hello, I'm a little confused about this 2 constructs:
To access the vector object, I have to dereference the pointer to get it. I understand this...
1 2 3
|
vector<string> *vec = new vector<string>();
//OK: requires dereferencing to
(*vec).push_back("some string");
|
However, when I have a pointer to an array of vector<string> type, I don't need to dereference! Why is this?
1 2 3 4
|
vector<string> *pvec = new vector<string>[10];
pvec[2].push_back("the string"); //OK! no dereference needed
//ERROR: indirection requires pointer operand
(*(pvec[2])).push_back("the string");
|
Could somebody please explain to me, what's the difference between the 2 cases?
Thanks in advance!
Topic archived. No new replies allowed.