The following code compiles if and only if I remove Foo's custom destructor.
struct Foo {
std::unique_ptr <int> bar;
~Foo (void) {} // This Line
};
std::vector <Foo> foos;
foos.push_back (Foo ());
Here is what I think I understand about the situation:
It fails because unique_ptrs
cannot be copied, and std::vector::push_back (thing)
calls the thing's
copy constructor. If I write Foo
a custom copy constructor which explicitly moves bar
, then everything will be fine.
However, disabling This Line
will cause the code to compile.
I thought that this should fail to compile even without This Line
, because I'm still attempting to push_back
a unique_ptr
.
Why does this succeed without the custom destructor, and why does adding the custom destructor cause it to fail?
Edit: using gcc -std=gnu++11
on Debian Linux 64-bit