class callback

// 定义回调函数申明
typedef void (CObject::*Test)();
#define tempCallback(_SELECTOR) (Test)(&_SELECTOR)

class tempClass
{
public:

	Test tempTestCall;
	CObject* m_obj;

	void init(CObject* obj, Test t)
	{
		tempTestCall = t;
		m_obj = obj;
	}

	void call_()
	{
		if (m_obj && tempTestCall)
		{
			(m_obj->*tempTestCall)();
		}
	}

private:

};

void CdfsafsaDlg::OnBnClickedButton1()
{
	tempClass tsc;
	tsc.init(this,tempCallback(CdfsafsaDlg::TestCalllBack));
	tsc.call_();
}

void CdfsafsaDlg::TestCalllBack()
{
	int a = 10;
	CString strTemp;
	strTemp.Format(_T("%d"),a);
	::MessageBox(NULL,strTemp,_T("tip"),MB_OK);
}

你可能感兴趣的:(class callback)