Question: C++ Dynamic Array Function Below I have the functions from the .h file and I need help with the constructor! template class dynarr { private:
C++ Dynamic Array Function
Below I have the functions from the .h file and I need help with the constructor!
template
class dynarr {
private:
int capacity;
dynElem *A;
public:
dynarr() : capacity(0), A(NULL);
dynarr(int N): capacity(N), A(new dynElem[N]){}
dynarr(const dynarr
~dynarr();
dynarr
dynElem & operator[](int ndx) throw(InvalidIndex);
int getCapacity();
void reserve(int newcap);
// if newcap <= capacity, does nothing;
// if capacity is 0, allocates a dynamic array of
// capacity newcap and makes A point to that array;
// otherwise allocates a new dynamic array newA of capacity
// newcap, copies values in A to newA, deletes A and sets
// A equal to newA
};
Constructor function
template
dynarr
{
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
