Add Reference Count Capability To your class with a template class

zhaozj2021-02-17  49

BECAUSE My System Can't Install Chinese IME, SO ... IN FACT, EVERYONE READ This Article Should Know My English is Very Pool.

// This template class is used to add "ref count" feature for any classtemplate class CRefObject: public T {public: DWORD AddRef (void) {return :: InterlockedIncrement ((LPLONG) & m_dwRef);} DWORD Release ( Void) {if (0 == m_dwref || 0 == :: InterlockedDecrement ((lplong) & m_dwref) {delete this; return 0;} return m_dwref;} // create an instance buf == 0 static crefObject * CREATEINSTANCE (VOID) {CREFOBJECT * P = NULL; P = New CrefObject (); Return P;} protected: // Note: All T Must Have a Default Constructionor CrefObject (void): m_dwref 0) {} // i think define a "virtual" district - crefObject () {}; DWORD M_DWREF;};

转载请注明原文地址:https://www.9cbs.com/read-30587.html

New Post(0)