#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
class Test
{
static const int size;
private:
char* pData;
public:
Test()
{
cout << "디폴트" << endl;
pData = new char[size];
}
Test(const Test& other)
{
cout << "복사" << endl;
pData = new char[size];
memcpy(pData, other.pData, size);
}
Test(Test&& other)
{
cout << "이동" << endl;
pData = other.pData;
other.pData = nullptr;
}
Test& operator=(const Test& other)
{
cout << "할당 연산자" << endl;
if (this == &other)
return *this;
delete[] pData;
pData = new char[size];
memcpy(pData, other.pData, size);
return *this;
}
Test& operator=(Test&& other)
{
cout << "이동 할당 연산자" << endl;
if (this == &other)
return *this;
delete[] pData;
pData = other.pData;
other.pData = nullptr;
return *this;
}
~Test()
{
delete[] pData;
}
};
const int Test::size = 100;
int _tmain(int argc, _TCHAR* argv[])
{
Test aaa;
Test bbb = aaa;
aaa = bbb;
aaa = std::move(bbb);
Test ccc = Test(std::move(aaa));
return 0;
}