• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            在VC2005中,只要知道類的名字,就可以動態創建類的實例

            CRuntimeClass::FromName

            Call 
            this function to retrieve the CRuntimeClass structure associated with the familiar name.
             
            static CRuntimeClass* PASCAL FromName(
               LPCSTR lpszClassName 
            );
            static CRuntimeClass* PASCAL FromName(
               LPCWSTR lpszClassName 
            );
             
            Parameters
            lpszClassName
            The familiar name of a 
            class derived from CObject.

            Return Value
            A pointer to a CRuntimeClass 
            object, corresponding to the name as passed in lpszClassName. The function returns NULL if no matching class name was found.

            完整代碼如下:
            #include <iostream>
            #include 
            <afxwin.h>
            using namespace std;
            class CMyClass:
                
            public CObject
            {   
                DECLARE_SERIAL(CMyClass)
            };
            IMPLEMENT_SERIAL(CMyClass,CObject,
            1)
            //注意,CMyClass必須從CObject派生必須實現了DECLARE_SERIAL, IMPLEMENT_SERIAL兩個宏。
              
            class CAge:
                
            public CObject
            {   
                DECLARE_DYNAMIC(CAge)
            };
            IMPLEMENT_DYNAMIC(CAge,CObject)
            int main()
            {
                
            // This example creates an object if CMyClass is defined.
                CAge * pMyObject=new CAge;
                CRuntimeClass
            * pMyRTClass= pMyObject->GetRuntimeClass();
                 
                CRuntimeClass
            * pClass = pMyRTClass->FromName("CMyClass");
                
            if (pClass == NULL)
                {
                   
            // not found, display a warning for diagnostic purposes
                   AfxMessageBox("Warning: CMyClass not defined");
                   
            return NULL;
                }
                 
                
            // attempt to create the object with the found CRuntimeClass
                CObject* pObject = pClass->CreateObject();
                cout 
            << pObject->GetRuntimeClass()->m_lpszClassName <<endl;
                system(
            "pause");
                
            return 0;
            }




            代碼2:
            #include <iostream>
            #include <afxwin.h>
            using namespace std;
            class CMyClass:
                
            public CObject
            {   
                DECLARE_SERIAL(CMyClass)
            };
            IMPLEMENT_SERIAL(CMyClass,CObject,1)
              
            int main()
            {
                CObject* pObject = (RUNTIME_CLASS(CObject))->CreateObject("CMyClass");
                cout << pObject->GetRuntimeClass()->m_lpszClassName <<endl;
                system("pause");
                
            return 0;
            }



            //代碼3
            #include <iostream>
            #include 
            <afxwin.h>

            using namespace std;

            class CMyA:public CObject{
                DECLARE_DYNCREATE(CMyA);
            public:
                
            void show(){
                    cout 
            << "CMyA::show()" << this-><<endl;
                }
                
            int n;
            };
            IMPLEMENT_DYNCREATE(CMyA,CObject);


            int main(int argc, char* argv[]) {
                CObject
            * a = RUNTIME_CLASS(CMyA)->CreateObject();
                CMyA
            * b = (CMyA*)a;
                b
            ->= 5;
                b
            ->show();
                
            return 0;
            }

            //注意代碼1和代碼3之間的區別.

            posted on 2010-10-26 17:04 天下 閱讀(533) 評論(1)  編輯 收藏 引用

            評論

            # shi 2010-12-22 09:29 uk dress

            good post...I like this very much...  回復  更多評論   

            <2011年3月>
            272812345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            26uuu久久五月天| 久久久无码精品亚洲日韩按摩 | 久久亚洲中文字幕精品一区| 欧美久久亚洲精品| 狠狠色狠狠色综合久久| 亚洲国产精品久久久久网站| 青春久久| 狠狠干狠狠久久| 亚洲国产精品综合久久网络 | 久久精品国产亚洲综合色| 久久综合九色综合久99| 久久久久久综合网天天| 亚洲午夜久久久精品影院| 午夜天堂精品久久久久| 色综合色天天久久婷婷基地| A级毛片无码久久精品免费| 久久久精品免费国产四虎| 7777久久久国产精品消防器材| 国产亚洲成人久久| 国产99精品久久| 2021国产精品午夜久久| 久久精品18| 久久人妻少妇嫩草AV无码专区| 亚洲精品WWW久久久久久 | 久久人人爽人人爽人人爽| 久久国产精品免费一区二区三区| 久久综合狠狠综合久久综合88| 亚洲国产小视频精品久久久三级| 国产精品日韩深夜福利久久| 国产午夜精品理论片久久影视| 激情伊人五月天久久综合| 久久精品国产精品亚洲精品| 久久久久久午夜精品| 久久伊人精品一区二区三区| 香蕉久久久久久狠狠色| 四虎国产精品成人免费久久 | 无码人妻精品一区二区三区久久| 久久只有这精品99| 99精品国产综合久久久久五月天 | 久久综合给合综合久久| 久久精品国产69国产精品亚洲|