// 25_25-16.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>

using namespace std;

class MPcls {
public:
	int d1, d2;
	void add() {
		cout << "add:" << d1 << "+" << d2 << "=" << d1+d2 << '\n';
	}
	void sub() {
		cout << "sub:" << d1 << "-" << d2 << "=" << d1-d2 << '\n';
	}
	void disp(int mode) {
		if (mode == 1) {
			cout << "d1=" << d1 << '\n';
		}
		if (mode == 2) {
			cout << "d2=" << d2 << '\n';
		}
		if (mode == 2) {
			cout << "d1" << d1 << " d2=" << d2 << '\n';
		}
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	MPcls a, b;	// MPclsオブジェクトを宣言
	int MPcls:: *dp;	// int型データメンバへのポインタdp
	void (MPcls:: *fp0)();	// 引数がなく戻り値がvoid型であるメンバ関数へのポインタfp0
	void (MPcls:: *fp1)(int a);	// ひとつのint型引数をもち戻り値がvoid型であるメンバ関数へのポインタfp1

	// メンバ名による通常処理(参考)
	a.d1 = 110;
	a.d2 = 100;
	a.add();
	a.sub();
	a.disp(1);
	a.disp(2);
	a.disp(3);

	// メンバポインタによる処理
	dp = &MPcls::d1;

	a.*dp = 220;
	b.*dp = 440;

	dp = &MPcls::d1;
	a.*dp = 200;
	b.*dp = 400;

	fp0 = &MPcls::add;
	(a.*fp0)();
	(b.*fp0)();

	fp0 = &MPcls::sub;
	(a.*fp0)();
	(b.*fp0)();

	fp1 = &MPcls::disp;
	(a.*fp1)(3);
	(b.*fp1)(3);

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);
	
	return 0;
}

