How do I initializing a pointer to vector of pointer to string?
When I try this I get this for an error..
"Run-Time Check Failure #3 - The variable 'namesPtr' is being used without being initialized."
1 2 3 4 5 6 7 8 9 10 11 12
#include <string>
using std::string;
#include <vector>
using std::vector;
int main ()
{
vector<string*>* namesPtr;
namesPtr->push_back(new string("value"));
}
That's because namesPtr doesn't point to anything. Either vector<string*>* namesPtr = new vector<string*>(); or vector<string*>* namesPtr = &some_other_vector_of_pointers_to_strings;
Also note this isn't Java. You don't have to allocate everything with new. Here, I wouldn't recommend using pointers at all, as it just opens up the possibility of memory leaks and doesn't provide any real benefit.