Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the move constructor implicitly deleted when a destructor is defined

Tags:

c++

c++17

c++14

I am wondering why the committee has decided that a move constructor is implicitly deleted when a destructor is defined.

#include <iostream>
#include <vector>
#include <memory>

struct A { 
  ~A(){}; 
  std::unique_ptr<int> a;
};


int main()
{
    A a;
    A b = std::move(a);
}

http://coliru.stacked-crooked.com/a/c0c067fc51260794

Is there any utopic use-case for which this rule "of not default moving the members" makes sense?

like image 428
Gabriel Avatar asked Oct 15 '25 14:10

Gabriel


1 Answers

The logic is: if you define a destructor that implies it releases resources there, so that compiler-generated constructors and assignments are probably not adequate.

like image 89
Maxim Egorushkin Avatar answered Oct 17 '25 05:10

Maxim Egorushkin