// 26_26-10.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>

using namespace std;

class Mystr {
private:
	char *text;
	int len(char *s) {
		int n = 0;
		while (*s++) {
			++n;
		}
		return n;
	}
	void cpy(char *s) {
		for (int n = 0; *(text+n) = *s++; n++) {;}
	}
public:
	Mystr(char *ss = "");
	Mystr(const Mystr& obj);
	~Mystr() { delete[] text; }
	void disp() { cout << "text=" << text << '\n'; }
	Mystr &operator=(const Mystr &obj);
};

Mystr::Mystr(char *ss)
{
	text = new char[len(ss)+1];
	cpy(ss);
}

Mystr::Mystr(const Mystr &obj)
{
	text = new char[len(obj.text)+1];
	cpy(obj.text);
}

Mystr &Mystr::operator =(const Mystr &obj)
{
	if (this != &obj) {
		delete[] text;
		text = new char[len(obj.text)+1];
		cpy(obj.text);
	}
	return *this;
}

int _tmain(int argc, _TCHAR* argv[])
{
	Mystr s1("abcd");
	Mystr s2 = s1;
	s2.disp();

	Mystr s3;
	s3 = s1;
	s3.disp();

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

