Dreading memory leaks, I would like to make sure I have an understanding of the following code:
//vector initialized to allocate 10 string objects
vector<string> *pvec1 = new vector<string>(10);
delete pvec1;
//10 vector<string> objects
vector<string> *pvec2 = new vector<string>[10];
pvec2[0].push_back("test1");
delete [] pvec2;
1> Would executing the preceding code create a memory leak? I am adding a string object to the first vector<string> object -- wouldn't that allocate more memory on the heap? If so, then wouldn't I have to execute: delete pvec[0];
? Which doesn't work.
2> Is there a way to allocate (using new) 10 vector<string> objects, each with 10 string objects allocated? Such as: vector<string> **pvec2 = new vector<string>(10)[10];
? Which also doesn't work.
Thanks!