// 25_25-11.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>

using namespace std;

class MyCls {
public:
	int x, y;
	void copy_and_clear(MyCls& obj);
};

void MyCls::copy_and_clear(MyCls &obj) {
	if (&obj == this) {	// 引数が自分自身なら何もしない
		return;
	}
	*this = obj;
	obj.x = obj.y = 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
	MyCls d1, d2;

	d2.x = 10;
	d2.y = 20;
	d1.copy_and_clear(d2);
	cout << "d1: " << d1.x << " " << d1.y << '\n';
	cout << "d2: " << d2.x << " " << d2.y << '\n';

	d1.copy_and_clear(d1);
	cout << "d1: " << d1.x << " " << d1.y << '\n';

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

