// 25_25-15.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>

using namespace std;

class Stmbr {
private:
	int nn;
	static int ct;
public:
	Stmbr(int n = 0) { nn = n; ++ct; }
	Stmbr(const Stmbr& obj) { nn = obj.nn; ++ct; }
	~Stmbr() { --ct; }
	void disp();
	static void st_disp();
};

int Stmbr::ct = 0;	// 静的データメンバctの実体を定義

void Stmbr::disp()
{
	// 通常メンバnnも静的メンバctもアクセス可
	cout << "ct=" << ct << " nn=" << nn << '\n';
}

void Stmbr::st_disp()
{
	// cout << nn << '\n';	// これはエラー。thisが渡されないのでアクセス不可
	cout << "CT=" << ct << '\n';
}

int _tmain(int argc, _TCHAR* argv[])
{
	// (1)まだ宣言はない
	Stmbr::st_disp();

	// (2)d1を宣言
	Stmbr d1 = 10;
	d1.disp();
	d1.st_disp();

	// (3)d2(d1)を宣言
	Stmbr d2(d1);
	d2.disp();
	d2.st_disp();

	// (4)new Stmbr[6]を宣言
	Stmbr *pp = new Stmbr[6];
	pp->disp();
	d1.st_disp();
	d2.st_disp();
	pp->st_disp();
	Stmbr::st_disp();

	// (5)delete[]を実行
	delete[] pp;
	d1.st_disp();

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

