c++ - allocated but not initialized -


i have met allocated not initialized issue.

here part of code:

void test2(vector<string> names, int num) // test {     const char  **tmp = new const char *[num]; // issue happends here.     for(int = 0; < num; ++)         tmp[i] = names[i].c_str(); // not inialization???     //call function using tmp     delete []tmp;  } 

well in line 3 of code, got issue: assigning: "tmp" = "new char const *[num]", allocated not initialized.

i believe got confused 2-d arrays allocations , initialization. think tmp const char * array, , want convert vertor const char **;

then in code, right use new , delete here?

i know if 2d array int*, if want assign value it, need new int[num], loop new int[]; how case here?

can me piece of code?

don't use const in situation because you're allocating data post-initialization.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -