#include <iostream>
using std::cin; using std::cout; using std::endl;
class Array
{
private:
size_t size; //<------------------------------------------------------------+
int *a; // |
// |
public: // |
// Default constructor: |
Array(size_t size = 0) : // |
size(size), a(size ? new int[size] : nullptr) // |
//Dùng initialization list thì phải để ý thứ tự khai báo dữ liệu----+
//Nếu khai báo a trước size thì sẽ bị lỗi
{ }
// Copy constructor:
Array(const Array &other) :
size(other.size), a(size ? new int[size] : nullptr)
{
for (int i = 0; i < size; ++i)
a[i] = other.a[i];
}
// Destructor:
~Array() {
delete[] a;
}
// Move constructor:
Array(Array &&other) :
size(other.size), a(other.a)
{
other.a = nullptr;
}
void swap(Array &other)
{
std::swap(size, other.size);
std::swap(a, other.a);
}
// Copy assignment operator cũng là move assignment operator:
Array& operator=(Array other)
{
this->swap(other);
return *this;
}
};
int main()
{
}