[ create a new paste ] login | about

Link: http://codepad.org/S3UcFYYu    [ raw code | output | fork ]

C++, pasted on May 2:
#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()
{

}


Output:
1
2
Line 36: error: expected ',' or '...' before '&&' token
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: