mardi 3 novembre 2015

Implicit use of destructor

I have a class with a deleted destructor (in practice, it needs outside help to be destroyed):

struct indestructible {
    indestructible(indestructible&&);
    ~indestructible() = delete;
};

When I try to use its move constructor, the compiler complains:

struct user {
   indestructible ind;
   user(indestructible&& ind) : ind(std::move(ind)) {}
};

indestructible.cc:11:3: error: attempt to use a deleted function
user(indestructible&& ind) : ind(std::move(ind)) {}
^
indestructible.cc:6:3: note: '~indestructible' has been explicitly marked  deleted here
    ~indestructible() = delete;

What's going on? there are no other members that could throw, and neither does the constructor body, so why is there any cause for the move constructor to invoke the destructor?

Aucun commentaire:

Enregistrer un commentaire