I am getting some errors I dont understand with this file. I'm trying to break down this string into pieces. I supposed to take the parts of the string that are within parentheses out and make them into a new string. It is supposed to do this until the string is empty.
|22|error: variable-sized object 'functions' may not be initialized|
|364|error: too many arguments to function 'void* malloc(size_t)'|
|50|error: at this point in file|
string newfunction = "(" + function + ")";
int functionlength = newfunction.size();
char * functions[functionlength] = newfunction;
You are assigning a variable newfunction of C++ string datatype to an array of char * which may mean only the first element in the array functions is initialized. The rest maybe undefined.
pData = (string*) malloc (i,sizeof(string));
The C function malloc do not take 2 arguments as said by the warning void* malloc(size_t) which indicate only 1 argument.
I am confused by pData. I am not sure what it is meant to be/do.
Good question I am also confused. Is this code written by you or by others ? It just malloc and then never assign values to it. Maybe someone can understand the original author intention ?
Also note that you should NEVER allocate complex types like string with malloc (unless you use placement new later) as malloc does not call the constructor.
Using string without having its constructor called would have disasterous results.