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

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

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -