Jump to content

C++: Difference between revisions

201 bytes removed ,  15 April
Line 662: Line 662:
* Destructor
* Destructor
* Copy constructor
* Copy constructor
* Copy assignment operator
* Assignment operator


[[Wikipedia: Rule of three (C++ programming)#Rule of five | Rule of five]]
[[Wikipedia: Rule of three (C++ programming)#Rule of five | Rule of five]]
* Move constructor
* Move constructor
* Move assignment operator
* Swap function


{{hidden | Example RAII Class |
{{hidden | Example RAII Class |
Line 701: Line 701:
     }
     }


     // copy assignment
     // assignment operator
     dumb_array& operator=(dumb_array other) // (1)
     dumb_array& operator=(dumb_array other) // (1)
     {
     {
Line 719: Line 719:
         swap(first.mSize, second.mSize);
         swap(first.mSize, second.mSize);
         swap(first.mArray, second.mArray);
         swap(first.mArray, second.mArray);
    }
    // move constructor
    dumb_array(dumb_array&& other) noexcept ††
        : dumb_array() // initialize via default constructor, C++11 only
    {
        swap(*this, other);
     }
     }