Anyway, I have a question about constructors.
In C, I might do something like this:
typedef struct some_struct{int *some_ptr;};some_struct *Constructor(int some_params){some_struct *temp;temp = (some_struct *)malloc(sizeof(some_struct));if(temp == NULL)return(NULL);temp->some_ptr = (int *)malloc(some_params * sizeof(int));if(temp->some_ptr == NULL){free(temp);return(NULL);}return(temp);}
As you can see, not only am I allocating an instance of some_struct, but I am also allocating some of the pointers inside some_struct. If there is a memory error, I return NULL and this is checked by the function calling the constructor.
How would this be done in C++? I know that I am basically changing the struct to a class and memory for the class is allocated by new outside of the constructor. At what point is the constructor function called during a call to new? If there are errors allocating memory for pointers in the class, is it possible to free the memory held by the allocated class from within the constructor? What is the exact purpose of a C++ constructor function?