std::unique_ptr compiler error: Members of a derived class cannot access private members of a base class

c++, c++11, compiler-errors, unique-ptr

Solution

You need to provide move operations for your type:

data(data&& other)
    : l(std::move(other.l))
{
}

data& operator=(data&& other)
{
    l = std::move(other.l);
    return *this;
}

And, since you'll have added a user-declared constructor, you'll also need a user-declared default constructor:

data() { }

My understanding is that your code is correct as-is, per the final C++11 language standard. Visual C++ does not fully implement the final specification for when move operations are implicitly generated (as of the Visual C++ 2012 RC). The specification for when implicit move operations are generated changed several times very late in the standardization process.

If you have a class type `C` that has any data member that is movable but noncopyable, Visual C++ will not generate an implicit move constructor or move assignment operator, and the implicit copy constructor and copy assignment operator are both suppressed by the presence of the move-only data member. In other words, if you want ot aggregate move-only types, you must provide the move operations for the aggregating class yourself.

(At least, this is my understanding from experimentation with the compiler.)

Problem

I get Compiler Error C2248 when i try to compile the following code: ``` #include <list> #include <memory> using namespace std; class data { public: static data parse() { data d; data::parse(d); return d; } list<std::unique_ptr<data>> l; private: static void parse(data& node) { } }; int main() { return 0; } ``` Why? How can i fix this? Note: I have no problem using `std::shared_ptr` instead of `std::unique_ptr`.

Original source

Related problems