Quick question, if I declare this pointer to a vector:
std::vector<int>* myVector = &someOtherVector;
Why does this not work?
*myVector[0] = 42;
And why does this work?
(*myVector)[0] = 42;
Thanks.
Quick question, if I declare this pointer to a vector:
std::vector<int>* myVector = &someOtherVector;
Why does this not work?
*myVector[0] = 42;
And why does this work?
(*myVector)[0] = 42;
Thanks.
*myVector[0] = 42; evaluates to *(myVector[0]) = 42; because operator[] has a higher priority than operator*(). As a result, you're trying to dereference an integer which causes the error.