資源簡介
C++實戰源碼-在類中實現事件(入門級實例218).zip
代碼片段和文件信息
//?Event.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“ioStream.h“
#include?“string.h“
class?CLoad;
typedef?void?(*TEvent)(CLoad?*?e);//事件指針
class?CLoad
{
private:
char?filename[10];//文件名
public:
TEvent?onload;//載入事件
void?Load(char?*FileName)
{
strcpy(filenameFileName);
cout?<“執行內部載入操作“?< if?(onload?!=?NULL)//是否存在事件
onload(this);//執行事件
}
char?*?GetFileName()
{
return?filename;
}
};
void?onload(CLoad*?e)//定義外部事件
{
cout?<“執行外部事件加載文件:“?<GetFileName()?<}
int?main(int?argc?char*?argv[])
{
CLoad?ld;
ld.onload?=?onload;//添加事件
ld.Load(“c:\\123.txt“);
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????755??2010-10-14?16:25??Event\Event.cpp
?????文件????????4524??2010-10-14?16:14??Event\Event.dsp
?????文件?????????535??2010-10-14?16:14??Event\Event.dsw
?????文件?????????292??2010-10-14?16:14??Event\StdAfx.cpp
?????文件?????????769??2010-10-14?16:14??Event\StdAfx.h
- 上一篇:C++實戰源碼-集郵冊中的郵票數量
- 下一篇:C++實戰源碼-斐波那契數列
評論
共有 條評論