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

正文內(nèi)容

com接口與對(duì)象-預(yù)覽頁(yè)

 

【正文】 sz) { return new CMyString(psz)。 if (p) { const char*psz = pFind(llo)。 void main() { IString *p。 if (p) { const char*psz = pFind(llo)。 virtual const char*Find(const char *psz)=0。 public: CMyString(const char * psz)。 int Length()。 p = CreateString(Hello)。 } }。 virtual char FindAt(int index)。 virtual void Load(const char *pszFile)。 ?新對(duì)象實(shí)現(xiàn)兩個(gè)接口: IString2和 IString –不打斷新的客戶與老的對(duì)象之間的關(guān)系 –但是客戶必須明確地知道對(duì)象是否實(shí)現(xiàn)了自己感興趣的接口 對(duì)象實(shí)現(xiàn)多個(gè)接口 ?假如對(duì)象實(shí)現(xiàn)了兩個(gè)接口 IString和 IPersist –客戶需要在 runtime時(shí)明確地知道接口的類(lèi)型信息,包括通過(guò)創(chuàng)建函數(shù)得到的初始接口類(lèi)型 – at runtime, 客戶可以靈活地從一個(gè)接口變換到另一個(gè)接口,如果對(duì)象不支持某個(gè)接口,客戶也有辦法知道 –回憶 RTTI(Runtime type identification) ?dynamic_cast ?RTTI依賴(lài)于編譯器的實(shí)現(xiàn) ?RTTI只能用于類(lèi)的繼承層次中 對(duì)象實(shí)現(xiàn)多個(gè)接口 (續(xù)一 ) ?所以我們需要自己構(gòu)造一套類(lèi)型機(jī)制,要求: –每個(gè)接口都要提供類(lèi)型轉(zhuǎn)換機(jī)制,能轉(zhuǎn)換到同一對(duì)象上實(shí)現(xiàn)的其他接口 –客戶只要得到了一個(gè)接口就可以得到其他的接口,所以創(chuàng)建函數(shù)可以返回任一個(gè)接口 –如果對(duì)象不支持某個(gè)接口,客戶必須能明確地知道,而不是發(fā)生異常 —— robust – Dynamic_cast 對(duì)象實(shí)現(xiàn)多個(gè)接口 (續(xù)二 ) ?一個(gè)對(duì)象實(shí)現(xiàn) IString2和 IString接口 : class IString { virtual void Delete()=0。 }。 else if (strcmp(psz,IString2)==0) return static_castIString2 *(this)。 const char*psz = pFind(llo)。 } }。 virtual void Load(const char *pszFile)=0。 else if (strcmp(psz,IPersist)==0) return static_castIPersist *(this)。 IPersist *p3。 if ((p3=(IPersist *)pDynamic_cast(IPersist))) p3Save(c:\\temp\\)。每個(gè)接口都有Delete函數(shù)?還是只有一個(gè)接口才有?進(jìn)一步, 什么時(shí)候刪除對(duì)象? ?客戶可能擁有多個(gè)指向?qū)ο蟮囊茫?每個(gè)引用各有自己的 lifetime ?每個(gè)引用從被有效賦值開(kāi)始,一直到生命周期結(jié)束,這期間被稱(chēng)為: outstanding reference 未完結(jié)引用 ?客戶管理每個(gè)引用的 lifetime, 也就是說(shuō)它要 顯式 地告訴對(duì)象引用無(wú)效了 對(duì)象的生命周期管理 (續(xù) ) ?每個(gè)對(duì)象要管理一個(gè)被稱(chēng)為引用計(jì)數(shù)(reference count)的整數(shù)值。 virtual void *Dynamic_cast(const char *psz)=0。 }。 virtual void Save(const char *pszFile)=0。 else m_psz[0] = 0。 } include class CMyString : public IString2, public IPersist { private: char *m_psz。 void DuplicatePointer()。 int Length()。 }。 else if (strcmp(psz,IPersist)==0) p = static_castIPersist *(this)。 if (p) { IString2 *p2。 if ((p2=(IString2 *)pDynamic_cast(IString2))) { char c = p2FindAt(3)。 } pDestroyPointer()。 if (NULL!=p) { pret= pDynamic_cast(pszinterface)。 virtual void DuplicatePointer()=0。 WORD Data2。 extern C const GUID CLSID_MYSPELLCHECKER = { 0x54bf6567, 0x1007, 0x11d1, { 0xb0, 0xaa, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} } 。 virtual ULONG __stdcall Release() = 0。 ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )( IUnknown __RPC_FAR * This)。 COM接口結(jié)構(gòu) 接口指針 指針 指針函數(shù) 1指針函數(shù) 2指針函數(shù) 3。 }。 void (*DeleteWord)( IDictionary * this, String)。 }。 virtual void DeleteWord(String) = 0。 }。 BO OL In se rtW o rd )( th is * , S tri n g )。 v o id F ree L ib rary (th is * )。 return。 if (result != S_OK) { pIDictionaryRelease()。 ...... QueryInterface實(shí)現(xiàn) ?與對(duì)象的定義有關(guān) ?IUnknown必須是個(gè)靜態(tài)接口指針,其他接口指針可以是動(dòng)態(tài)的 ?QueryInterface在返回接口之前,必須調(diào)用新接口的 AddRef函數(shù) QueryInterface實(shí)現(xiàn)舉例 class CDictionary : public IDictionary , public ISpellCheck { public : CDictionary()。 virtual ULONG AddRef() 。 IU n k n o w nID ic tio n a ryCD ic tio n a ryIU n k n o w nISp e llCh e c kQueryInterface實(shí)現(xiàn)舉例(續(xù)一) IDictio n a ry 的 v tab le 指針th is 指針I(yè)S p e ll Ch e c k 的 v tab le 指針CDictio n a ry的屬性數(shù)據(jù)Qu e ry In ter f a c eA d d RefRelea se......Qu e ry In ter f a c eA d d RefRelea se......IDictio n a ry成員函數(shù)IS p e ll Ch e c k成員函數(shù)v tab leQueryInterface實(shí)現(xiàn)舉例(續(xù)二) HRESULT CDictionary::QueryInterface(const IIDamp。 ((IDictionary *)(*ppv))AddRef() 。 return E_NOINTERFACE 。 ~CDictionary()。 virtual ULONG Release() 。 char *m_DictFilename[128]。 // ... initialize } ULONG CDictionary::AddRef () { m_Ref ++。 } 引用計(jì)數(shù)用法 ?客戶要引用接口時(shí) —— 增一操作 –調(diào)用 IUnknown::AddRef() ?客戶用完接口時(shí) —— 減一操作 –調(diào)用 IUnknown::Release() ?當(dāng)對(duì)象的引用計(jì)數(shù)為 0時(shí),釋放 ?當(dāng)組件中所有對(duì)象的引用計(jì)數(shù)為 0時(shí),卸載 ?AddRef和 Release的返回值不可靠 引用計(jì)數(shù)使用示例 // load the dictionary BOOL retValue = pIDictionaryLoadLibrary()。 pIDictionaryForWord AddRef()。 ...... // finally, release dictionary object pIDictionaryRelease ( )。 return (ULONG) m_Ref。 } return (ULONG) m
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1