push_back() appends an element to the end of a C++ vector. The operation may do more than place one value: when the vector grows, it can allocate a longer internal array and copy existing elements into it. section 6.2.2
Appending dates
An Appointments wrapper calls dates.push_back(date) to append Date objects. Instrumentation shows that appending can invoke a copy constructor for the argument, allocate a new array, copy existing dates, destroy the old elements, and destroy temporary copies. section 6.2.2
Listing 6.11 (Program 6.7 SurpriseVector-1): Appointments.h (poor performance)
#include <vector>
#include "Date.h"
using namespace std;
class Appointments
{
public:
vector<Date> get_dates() const { return dates; }
Date at(const int index) const { return dates[index]; }
void append(const Date date) { dates.push_back(date); }
void insert(const int index, const Date date)
{
dates.insert(dates.begin() + index, date);
}
void remove(const int index)
{
dates.erase(dates.begin() + index);
}
private:
vector<Date> dates; #1
};
#1 Private vector of Date objects
Inspect the Appointments wrapper to see push_back() used behind an append operation. section 6.2.2

