-
dynamic memory question
can anyone tell me why why you have to use something like
"
Code:
char ** codes;
codes = new char*[num_codes];
for (i = 0; i < num_codes; i++)
{ codes[i] = new char[AMOUNT]; }
"
for allocating memory yet
Code:
"codes = new char[num_codes][string_length]; "
gives you an error like
"cannot convert "`char (*)[6]' to `char**'" in assignment"
the background of this is that we have to write a "set" class to represent a set of codes each code is a 5 character c-string.
-
If you get the type right, then you can do the latter quite happily
Code:
char (*codes)[num_codes];
codes = new char[num_codes][string_length];
This is a pointer to an array.
A char** is a pointer to a pointer, and needs to be allocated in a different way.
-