vector<int> *te;
te->push_back(10);
You have declared a pointer to a vector
; you have not initialized it to point to a valid piece of memory yet. You need to construct a new vector using new
.
vector<int> *te = new vector<int>();
You should however not do this. There are very few reasons to maintain a pointer to a vector, and you just made it completely ineffective at managing its own internal memory.
Read a little bit about RAII. This is a technique used to manage dynamically allocated memory via the lifetime of an object. The vector
uses this method to clean up its internal, dynamically allocated storage when it goes out of scope.
Maintaining a pointer to the vector prevents it from working correctly, relying on you to call delete
yourself, essentially nullifying one major benefit of using a vector
over an array in the first place.