Question: template class Array { public: // Some standard Container type aliases using value_type = T; // Iterators are just pointers to objects of type T

template

class Array

{

public:

// Some standard Container type aliases

using value_type = T;

// Iterators are just pointers to objects of type T

using iterator = value_type*;

using const_iterator = const value_type*;

using reference = value_type&;

using const_reference = const value_type&;

using size_type = size_t;

using difference_type = ptrdiff_t;

//*****************************************************

// Default ctor.

// Initialize an empty Array.

// This method is complete, and does NOT need modification.

// Remember to use a _member initialization list_ for each ctor,

// like I have below for the default ctor.

Array ()

: m_size (0),

m_capacity (0),

m_array (nullptr)

{

}

// Size ctor.

// Initialize an Array of size "pSize", with each element

// set to "value".

explicit Array (size_t pSize, const T& value = T ())

: m_size (pSize),

m_capacity (pSize),

m_array (new T[m_capacity])

{

fill (begin (), end (), value);

}

// Insert an element at the back.

// If the capacity is insufficient, DOUBLE it.

// If the capacity is 0, increase it to 1.

void

push_back (const T& item)

{

insert(end(),item);

}

private:

// Stores the number of elements in the Array.

size_t m_size;

// Stores the capacity of the Array, which must be at least "m_size".

size_t m_capacity;

// Stores a pointer to the first element in the Array.

T* m_array;

};

Help with the push_back function in c++, please!

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 Databases Questions!