Dereference vector pointer to access element
问题 If i have in C++ a pointer to a vector: vector<int>* vecPtr; And i'd like to access an element of the vector, then i can do this by dereferncing the vector: int a = (*vecPtr)[i]; but will this dereferencing actually create a copy of my vector on the stack? let's say the vector stores 10000 ints, will by dereferencing the vecPtr 10000 ints be copied? Thanks! 回答1: 10000 int s will not be copied. Dereferencing is very cheap. To make it clear you can rewrite int a = (*vecPtr)[i]; as vector<int>&