freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

com接口與對(duì)象-文庫吧資料

2024-10-07 21:52本頁面
  

【正文】 typedef struct _GUID { DWORD Data1。 virtual void DestroyPointer()=0。 } 修改創(chuàng)建函數(shù) ?讓創(chuàng)建函數(shù)也正確地維護(hù)引用計(jì)數(shù) 接口整理 ?每個(gè)接口都需要下面的三個(gè)函數(shù) – Dynamic_cast – DuplicatePointer – DeletePointer ?把三個(gè)函數(shù)放到一個(gè)基接口中,所有的接口都從這個(gè)基接口派生 class IAnyInterface { virtual void *DynamicCast(const char *psz)=0。 if (NULL==pret) delete p。 CMyString *p = new CMyString(psz)。 } }。 p3DestroyPointer()。 p2DestroyPointer()。 int n = pLength()。 IPersist *p3。 } 客戶管理對(duì)象的生命周期 void main() { IString *p = CreateString(Hello)。 if (NULL!=p) m_refcount++。 else if (strcmp(psz,IString2)==0) p = static_castIString2 *(this)。 接口轉(zhuǎn)換時(shí)刻相當(dāng)于接口復(fù)制 void *CMyString::Dynamic_cast(const char *psz) { void *p = NULL。 void Load(const char *pszFile)。 char FindAt(int index)。 const char*Find(const char *psz)。 void DestroyPointer()。 ~CMyString()。 long m_refcount。 } void CMyString::DuplicatePointer() { m_refcount++。 } void CMyString::DestroyPointer() { if (0m_refcount) m_refcount。 實(shí)現(xiàn)引用計(jì)數(shù)的兩個(gè)操作 CMystring::CMyString(const char * psz) : m_psz( new char[psz ? strlen(psz)+1 :1]), m_refcount(0) { if ( psz ) strcpy(m_psz,psz)。 virtual void Load(const char *pszFile)=0。 virtual void DuplicatePointer()=0。 class IPersist { virtual void DestroyPointer()=0。 virtual int Length()=0。 virtual void DuplicatePointer()=0。 ?當(dāng)客戶通過復(fù)制獲得新的接口指針時(shí),引用計(jì)數(shù)加一,當(dāng)某個(gè)接口不用時(shí),減一 引用計(jì)數(shù)的兩個(gè)操作 ?我們用引用計(jì)數(shù)的兩個(gè)管理操作代替原來簡單的Delete函數(shù) class IString { virtual void DestroyPointer()=0。 ?為了有效地管理對(duì)象的生命周期,它應(yīng)該提供一些規(guī)則和操作,供客戶遵守和使用: ?規(guī)則:保持引用計(jì)數(shù)的確切含義,也就是記錄當(dāng)前 outstanding reference的數(shù)目。 對(duì)象實(shí)現(xiàn)多個(gè)接口 (續(xù)七 ) 接口的轉(zhuǎn)換 ?每個(gè)接口提供一個(gè)用于接口轉(zhuǎn)換的函數(shù) ?對(duì)象實(shí)現(xiàn)接口的時(shí)候,可以使用 C++編譯器本身提供的類型轉(zhuǎn)換功能 ?每個(gè)接口的 Dynamic_cast函數(shù)決定了客戶可以訪問其他哪些接口 對(duì)象的生命周期管理 ?對(duì)象只需要被刪除一次。 pDelete()。 if ((p2=(IString2 *)pDynamic_cast(IString2))) char c = p2FindAt(3)。 const char*psz = pFind(llo)。 if (p) { IString2 *p2。 return NULL。 else if (strcmp(psz,IString2)==0) return static_castIString2 *(this)。 }。 virtual void Save(const char *pszFile)=0。 class IPersist { virtual void Delete()=0。 pDelete()。 int n = pLength()。 if (p) { IString2 *p2。 return NULL。 對(duì)象實(shí)現(xiàn)多個(gè)接口 (續(xù)三 ) ?實(shí)現(xiàn) Dynamic_cast class CMyString : public IString2{...} void *CMyString::Dynamic_cast(const char *psz) { if (strcmp(psz,IString)==0) return static_castIString *(this)。 class IString2 : public IString { virtual char FindAt(int index)=0。 virtual int Length()=0。 virtual void *Dynamic_cast(const char *psz)=0。 }。 }。 virtual void Save(const char *pszFile)。 }。 virtual int Length()。 小結(jié) ?我們已經(jīng)建立起對(duì)象與客戶之間的基本通信方式 ?更高的要求: –接口的升級(jí) –增加新的功能 –生命周期管理 ?什么時(shí)候該刪除對(duì)象 ?多個(gè)客戶共享同一個(gè)對(duì)象,如何管理? 對(duì)象的進(jìn)化 ?在原有接口的基礎(chǔ)上增加新的功能,例如 class IString { virtual void Delete()。 pDelete()。 if (p) { const char*psz = pFind(llo)。 } include void main() { IString *p。 }。 const char*Find(const char *psz)。 virtual ~CMyString()。 刪除對(duì)象自身 include class CMyString : public IString { private: char *m_psz。 virtual int Length()=0。 如何刪除對(duì)象? ?刪除對(duì)象發(fā)生在客戶與對(duì)象建立聯(lián)系之后,所以比較好辦 ?但是不能用 delete ?可以讓對(duì)象自己把自己刪除 ?在 IString中增加一個(gè)方法 class IString { virtual void Delete()=0。 int n = pLength()。 if (pfn) { p = pfn(Hello)。 HANDLE h = LoadLibrary(c:\\temp\)。 創(chuàng)建對(duì)象 include typedef IString * (*PfnCreateString)(const char *psz)。 int n = pLength()。 p = CreateString(Hello)。 } 通過引出函數(shù)創(chuàng)建對(duì)象 extern C _declspec(dllimport) IString *CreateString(const char *psz)。 如何創(chuàng)建對(duì)象? ?不能使用 new ?DLL的唯一接口是引出函數(shù) ?可行方案:單獨(dú)提供一個(gè)引出函數(shù)供客戶調(diào)用 extern C _declspec(dllexport) IString *CreateString(const char *psz)。 int Length()。 ~CMyString()。 變量 偏移量 vptr 0 Find Length vtable 純虛接口的使用? ?假如有一個(gè) C++對(duì)象實(shí)現(xiàn)了 IString ?客戶怎么使用? –怎么拿到 vtable接口 include class CMyString : public IString { private: char *m_psz。
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1