#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

class strtype {
	char *p;
	int len;
public:
	strtype(char *ptr);
	~strtype();
	void show();
};

strtype::strtype(char *ptr)
{
	int l = strlen(ptr);
	cout << "pにメモリを割り当てる。\n";
	this->p = (char *)malloc((l + 1) * sizeof(char));
	if (!p) {
		cout << "メモリ割り当てエラー\n";
		exit(1);
	}	
	strcpy(this->p, ptr);
	this->len = l;
}

strtype::~strtype()
{
	cout << "pを解放する。\n";
	free(p);
}

void strtype::show()
{
	cout << p << "-長さ:" << len << "\n";
}

int main()
{
	strtype s1("This is a test."), s2("I like C++.");
	s1.show();
	s2.show();
	s2 = s1;
	s1.show();
	s2.show();	
	return 0;
}