Compiling the below program with -std=c++11 fails, "error: call to deleted constructor of 'Foo'". This seems incorrect since C++11 explicitly added a new single argument vector resize method that is supposed to default-construct elements rather than copy them. --- #include <vector> class Foo { public: Foo() {} Foo(const Foo&) = delete; }; int main() { std::vector<Foo> vec; vec.resize(42); // error: call to deleted constructor of 'Foo' } --- By contrast, the following program using the vector size constructor works ok: --- #include <vector> class Foo { public: Foo() {} Foo(const Foo&) = delete; }; int main() { std::vector<Foo> vec(42); // compiles fine }
(In reply to Eric Friedman from comment #0) > This seems incorrect since C++11 explicitly added a new single argument > vector resize method that is supposed to default-construct elements rather > than copy them. It default constructs the new elements but when the vector reallocates its storage the existing elements need to be moved or copied to the new storage. Your type is neither movable nor copyable. [vector.capacity] Requires: T shall be MoveInsertable and DefaultInsertable into *this.