I'm reading through c++ primer and i've come to an exercise that i don't really understand.
The exercise:
Write a program to read strings into a vector. Now, copy that vector into an array of character pointers. For each element in the vector, allocate a new character array and copy the data from the vector element into that character array. Then insert a pointer to the character array into the array of character pointers.
I'm not quite sure what the exercise is telling me to do, and if im doing it the right way.
Your code is invalid from the point of view of the C++ Standard. The size of an array shall be a constant expression known during compilation. So this statement is incorrect
Would this make it legal?
I remember reading something about, when you allocate an array dynamically, you can do it without knowing its size during compilation.
I am a little bit confused about what this this line does: char **pointerArray;
This doesn't sound right. How would any self-reallocating container work in this model?
He is right. Any self-reallocating container uses dynamic memory. Arrays are static memory, the memory is allocated at compile time.
Dynamic memory is different as it can be allocated in runtime.
A vector is actually an object that uses dynamic memory. It has been tested for memory leaks, which are a great factor to take into account when using dynamic memory.