Assume the following piece of code to move an object of type A into av (vector):
#include <memory>
#include <vector>
struct A
{
~A() {};
std::unique_ptr<int> an_int;
};
int main(int argc, char* argv[])
{
std::vector<A> av;
av.push_back(A());
return 0;
}
This will fail to compile as is. However if I do not implement the destructor ~A() {}, it will work just fine. The compiler hints at some missing (deleted) copy constructor, but I fail to see where that applies here (as I am only doing move operations)
What is the relationship between the unique_ptr and the custom destructor that makes the code fail to compile? is there a simple work around for this?
Thanks.