Question: Compile a class template called MyArray which contains two data members: one called size of type int, and one pointer called myArrayPtr of type parameter

Compile a class template called MyArray which contains two data members: one called size of type int, and one pointer called myArrayPtr of type parameter T. Your class should

(a) Include a constructor that initializes the data member size, allocates memory space (for the array of size elements) to be pointed to by myArrayPtr using the new operator

(b) Include a copy constructor that initializes a MyArray object by making a copy of an existing MyArray object.

(c) Include a destructor that releases the memory allocated by new in the constructor.

(d) Provide a set function to set the ith element of the array and a get function to return the ith element of the array.

(e) Provide a toString member function which returns the string representation of a MyArray object, i.e., return the values of all the elements in the array as a comma delmited list.

have a main function to test your class, and the member functions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!