• <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 天下 閱讀(535) 評論(1)  編輯 收藏 引用

            評論

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

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

            <2012年1月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            中文字幕热久久久久久久| 久久e热在这里只有国产中文精品99| 久久青青草原精品国产不卡| 久久综合日本熟妇| 亚洲国产天堂久久久久久| 久久婷婷五月综合97色| 99久久亚洲综合精品成人| 亚洲欧美成人综合久久久| 久久九九久精品国产免费直播| 伊人久久大香线蕉综合网站| 无码人妻久久一区二区三区蜜桃| 久久婷婷色综合一区二区| 精品熟女少妇a∨免费久久| 国产高清国内精品福利99久久| 久久人妻少妇嫩草AV无码专区| 无码精品久久久天天影视| 久久国产视屏| 国产精品久久久久乳精品爆| 99久久99这里只有免费费精品| 久久久久久午夜精品| 亚洲精品无码专区久久同性男 | 1000部精品久久久久久久久| 人妻丰满AV无码久久不卡| 精品久久久中文字幕人妻| 波多野结衣AV无码久久一区| 亚洲国产精品成人久久| 精品国产一区二区三区久久久狼| 97久久久精品综合88久久| 久久国产成人亚洲精品影院 | 99re这里只有精品热久久| 久久亚洲精品中文字幕三区| 蜜臀久久99精品久久久久久| A级毛片无码久久精品免费| 久久91精品国产91久久麻豆 | 中文精品久久久久人妻不卡| 精品国产乱码久久久久久1区2区| 久久996热精品xxxx| 久久亚洲精品国产精品| 无码8090精品久久一区| 99久久免费国产特黄| 亚洲国产精品无码久久|