Below is the minimalist problem of the code:
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());
}
Above code compiles fine, unless the destructor is uncommented. For my requirement, I need to have a body of ~B()
explicitly defined.
How can I define the body of destructor with the unique_ptr
co-existing in the same class?
Note: Tried defining = default
versions of copy & move constructor to no avail. In my real code, unique_ptr<int>
is unique_ptr<forward_declared_class>
. Couldn't locate this problem in SO, though I am sure it must be present. Feel free to mark as dupe.