The following is a minimal code problem:
struct B { B () = default; //~B () {}; // error: use of deleted function 'B& B::operator=(const B&)' std::unique_ptr<int> m_pB = nullptr; }; int main () { std::vector<B> vB; vB.erase(vB.begin()); }
The above code compiles fine if the destructor is not uncommented. For my requirement, I need an explicit definition of the body ~B() .
How can I define a destructor body with unique_ptr coexisting in the same class?
Note I tried the definition = default of the copy and move constructor versions to no avail. In my real code, unique_ptr<int> has unique_ptr<forward_declared_class> . This problem could not be found in SO, although I am sure that it should be present. Feel free to flag as cheating.
c ++ c ++ 11 destructor compiler-errors unique-ptr
iammilind
source share