The following code compiles if and only if I delete the custom destructor Foo.
struct Foo {
std::unique_ptr <int> bar;
~Foo (void) {}
};
std::vector <Foo> foos;
foos.push_back (Foo ());
Here is what I think of the situation:
It does not work because it unique_ptrscannot be copied, but std::vector::push_back (thing)calls the thing'scopy constructor . If I write Foomy own copy constructor that explicitly moves bar, then everything will be fine.
However, disabling This Linewill compile the code.
I thought that this should not compile even without This Line, because I'm still trying push_backa unique_ptr.
, ?
: gcc -std=gnu++11 64- Debian Linux