Given the base class for several derived classes, the goal was to create a wrapper class that allowed the STL container to see objects with the base interface, an event, although different derived classes could actually be added to the container. (See Extracting data from a heterogeneous std :: list ).
After some involvement, I came up with a new derived class that was a wrapper around the unique_ptr base class. However, the move constructor confuses me.
class Base { friend class BaseWrapper; virtual Base * clone () const = 0; public: virtual ~Base () {}
This does not compile with g ++ 4.7.2 .
Now, to use BaseWrapper , I can implement a public move constructor as follows:
BaseWrapper (BaseWrapper &&bw) { ptr_.swap(bw.ptr_); }
And it works great . But, if I make it private, it will not compile .
However, I found that instead of the above, I can instead create a private copy constructor (making it publicly available, of course):
BaseWrapper (BaseWrapper &bw) { ptr_.swap(bw.ptr_); }
Can someone tell me if this should work, and why or why not? If it should work, why can't I make the move constructor private?
You can follow this link to the toy program illustrating the above in a more complete way.