fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class M{
  5. public: int database=0;
  6. M& operator=(M&& other){ //<--- change from "M&&" to "M&" will make it compilable
  7. this->database=other.database;
  8. other.database=0;
  9. return *this;
  10.  
  11. }
  12. M(M &&other) {
  13. *this = std::move(other);
  14. }
  15. M (M& m)=default;
  16. M ()=default;
  17. };
  18. class B{
  19. public: M shouldMove;
  20. };
  21.  
  22. int main() {
  23. B b;
  24. b.shouldMove.database=5;
  25. B b2=std::move(b); //<--- error: use of deleted function 'B::B(B&&)'
  26. std::cout<< b.shouldMove.database <<std::endl;
  27. std::cout<< b2.shouldMove.database <<std::endl;
  28. return 0;
  29. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
0
5