• <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中,只要知道類的名字,就可以動(dòng)態(tài)創(chuàng)建類的實(shí)例

            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派生必須實(shí)現(xiàn)了DECLARE_SERIAL, IMPLEMENT_SERIAL兩個(gè)宏。
              
            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之間的區(qū)別.

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

            評(píng)論

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

            good post...I like this very much...  回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            <2012年10月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評(píng)論

            中文字幕精品久久| 色婷婷综合久久久久中文| 人妻无码精品久久亚瑟影视| 亚洲国产精品一区二区三区久久| 久久影视综合亚洲| 久久精品九九亚洲精品| 狠狠精品久久久无码中文字幕 | 久久久久亚洲精品天堂| 久久99精品国产99久久| 亚洲va久久久久| 大伊人青草狠狠久久| 久久无码AV一区二区三区| 久久综合九色综合精品| 99精品国产99久久久久久97 | 欧美牲交A欧牲交aⅴ久久| 久久精品成人一区二区三区| 国产91色综合久久免费| 无码精品久久久天天影视 | 国产69精品久久久久APP下载| 精品久久久久久久久中文字幕| 亚洲伊人久久精品影院| 中文字幕无码久久人妻| 久久夜色精品国产亚洲av| 青青青青久久精品国产| 国产精品99久久精品| 久久综合亚洲欧美成人| 亚洲色欲久久久综合网东京热| 久久久久久亚洲精品无码| 色综合久久久久| 国产高清美女一级a毛片久久w| 久久精品9988| 99久久精品免费| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲熟妇无码另类久久久| 亚洲精品国产第一综合99久久| 亚洲国产成人久久综合野外| 亚洲欧美一区二区三区久久| 亚洲AV日韩精品久久久久久久| 人妻无码αv中文字幕久久| 无码人妻久久一区二区三区免费 | 伊人久久精品线影院|