vendredi 26 février 2016

In-class member initializer of unique_ptr to nullptr error with explicitly defined default constructor

Unfortunately I haven't been able to reproduce this with a minimal example, but I have a class that assigns a unique_ptr to nullptr using an in-class member initializer. If I use MyClass(){}, all is well. If I use MyClass() = default, I get:

conversion from 'std::nullptr_t' to non-scalar type 'std::unique_ptr<OtherClass>' requested

This is what a minimal example would look like (note that the below compiles fine):

#include <memory>

class OtherClass{};

class Test
{
    std::unique_ptr<A> data = nullptr;
public:

    //Test() {} // works fine
    Test() = default; // compiler error

};

int main()
{
    Test test;
}

Any suggestions on what I should be looking for? I.e. can you tweak this example to break it with the same sort of error?

Aucun commentaire:

Enregistrer un commentaire