How could I initialize a two dimensional char pointer in C++ class -


class tool { public:     tool();     ~tool();  private:     char **s; };  char *s1[]={"hello","world"}; 

how can initialize s , make same s1?

s={"hello","world"} 

doesn't seem work.

while use std::vector<std::string>, feel it's more beneficial directly answer question.

char** s pointer pointer; possibly pointer first pointer in array of pointers.

char* s1[] array of pointers const data (and should have been made const).

if want s work s1, first need allocate array of pointers, reason std::vector recommended others. new, have release allocated memory @ point. using new directly prone leaks. std::vector release allocated memory when object destructed. call delete[] in destructor if wanted to.

when array has been allocated, need std::copy array of pointers in s1 array of pointers in s. it's not single assign operation.


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -