Advertisement
maxim_shlyahtin

constr

Oct 13th, 2023
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. void Field::field_swap(Field& other){
  2.     std::swap(height, other.height);
  3.     std::swap(width, other.width);
  4.     std::swap(field, other.field);
  5.     std::swap(starting_cell, other.starting_cell);
  6.     std::swap(finishing_cell, other.finishing_cell);
  7. }
  8.  
  9. Field::Field(Field&& other){
  10.     this->field_swap(other);
  11. }
  12.  
  13. Field::Field(const Field& other){
  14.     this->width = other.width;
  15.     this->height = other.height;
  16.     this->starting_cell = other.starting_cell;
  17.     this->finishing_cell = other.finishing_cell;
  18.     Cell **tmp;
  19.     tmp = new Cell*[this->height];
  20.     for(int y = 0; y < other.height; y++){
  21.         tmp[y] = new Cell[this->width];
  22.         for(int x = 0; x < other.width; x++)
  23.             tmp[y][x] = other.field[y][x];
  24.     }
  25.     this->field = tmp;
  26. }
  27.  
  28. Field &Field::operator=(const Field& other){
  29.     if(this != &other)
  30.         Field(other).field_swap(*this);
  31.     return *this;
  32. }
  33.  
  34. Field &Field::operator=(Field&& other){
  35.     if(this != &other)
  36.         this->field_swap(other);
  37.     return *this;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement