Question: C++ - bool initilize(int size, int val = 0)- This function will allocate space for the pointer called mArray and fill it with val.
C++ - bool initilize(int size, int val = 0)-\ \ This function will allocate space for the pointer called mArray and fill it with val. Notice that this function has a default argument which sets all elements to 0 if nothing is specified. This function should first check to see if the pointer is not NULL. If it is not NULL then the memory associated with the pointer should be deleted so that you avoid a memory leak. This function should then allocate space for the pointer to create the array. You should use size for the number of bytes to allocate. This function also needs to check to make sure the memory was allocated. If it wasn't the function should simply return false. If the memory was allocated then the size variable in the class should be set and ar filled with val. If everything succeeds then the function will return true. Make sure that the private variable mSize is set to the size of the array.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
