Why does the following code not work with g++
version 4.9.2? If I try to build it the compiler complains about the missing copy constructor in the line where the vector is told to reserve more memory.
#include <vector>
class Number
{
public:
explicit Number(const int& i) : _value(i) {}
Number(const Number& other) = delete;
Number& operator=(const Number& other) = delete;
private:
int _value;
};
int main(int argc, char** argv)
{
std::vector<Number> numbers;
numbers.reserve(8);
return 0;
}
Why would the compiler even try to call the deleted copy constructor when the storage size of the vector is increased? There are no objects inside the vector anyway.