{"id":174,"date":"2014-06-05T19:54:04","date_gmt":"2014-06-05T10:54:04","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=174"},"modified":"2014-06-05T19:54:04","modified_gmt":"2014-06-05T10:54:04","slug":"runtime_class-%eb%a9%94%ed%81%ac%eb%a1%9c-%ec%82%ac%ec%9a%a9","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=174","title":{"rendered":"RUNTIME_CLASS \uba54\ud06c\ub85c \uc0ac\uc6a9"},"content":{"rendered":"<pre id=\"code_snippet_40\" style=\"position:relative;width:100%;border:0;padding:0;\">#include &quot;stdafx.h&quot;\r\n#define DEBUG\r\n#define RUNTIME_CLASS(class_name) (&amp;class_name::class##class_name)\r\n#define DECLARE_DYNAMIC(class_name) static CRuntimeClass class##class_name;\r\n#define IMPLEMENT_DYNAMIC(class_name) CRuntimeClass class_name::class##class_name={(#class_name),sizeof(class_name),class_name::CreateObject};\r\n#define DECLARE_DYNCREATE(class_name) static CObject* CreateObject();\r\n#define IMPLEMENT_DYNCREATE(class_name) CObject* class_name::CreateObject(){return new class_name;}\r\n\r\nclass CObject;\r\n\r\n\/\/struct CRunTimeClass\r\nstruct CRuntimeClass{\r\n    char m_lpszClassName[21];\r\n\tint m_nObjectSize;\r\n\tCObject* (*pfnCreateObject)(); \/\/\ud568\uc218\ud3ec\uc778\ud2b8\r\n\r\n\tCObject* CreateObject();\r\n};\r\n\r\nCObject* CRuntimeClass::CreateObject(){\r\n\treturn (*pfnCreateObject)();\r\n}\r\n\r\nclass CObject {\r\npublic:\r\n\t\/\/static CRuntimeClass classCObject;\r\n\tDECLARE_DYNAMIC(CObject)\r\n\tvirtual CRuntimeClass* GetRuntimeClass()  const { return NULL;}\r\n\tvirtual ~CObject(){}\r\nprotected:\r\n\tCObject() {printf(&quot;CObject constructor\\n&quot;);}\r\n};\r\n\r\nCRuntimeClass CObject::classCObject={&quot;CObject&quot;,sizeof(CObject),NULL};\r\n\r\n\/\/class CAlpha\r\nclass CAlpha : public CObject\r\n{\r\npublic:\r\n\t\/\/static CRuntimeClass classCAlpha;\r\n\tDECLARE_DYNAMIC(CAlpha)\r\n\t\/\/static CObject* CreateObject();\r\n\tDECLARE_DYNCREATE(CObject)\r\n\tvirtual CRuntimeClass* GetRuntimeClass() const{\r\n\t\treturn &amp;classCAlpha;\r\n\t}\r\nprotected:\r\n\tCAlpha() {printf(&quot;CAlpha constructor\\n&quot;);\r\n\t};\r\n};\r\n\r\n\/\/CRuntimeClass CAlpha::classCAlpha={&quot;CAlpha&quot;,sizeof(CAlpha),CAlpha::CreateObject};\r\nIMPLEMENT_DYNAMIC(CAlpha)\r\n\r\n\/\/CObject* CAlpha::CreateObject(){\r\n\/\/\treturn new CAlpha;\r\n\/\/}\r\nIMPLEMENT_DYNCREATE(CAlpha)\r\n\r\nvoid main()\r\n{\r\n\t\/\/Create CAlpha\r\n\t\/\/CRuntimeClass* pRTCAlpha=RUNTIME_CLASS(CAlpha);\r\n\tCRuntimeClass* pRTCAlpha=(&amp;CAlpha::classCAlpha);\r\n\tCObject* pObj1;\r\n\r\n\tpObj1=pRTCAlpha-&gt;CreateObject();\r\n\t\/\/CAlpha\uc758 &amp;OnCreate()\uac00 \ub300\uc785(\ud568\uc218\ud3ec\uc778\ud130\uc5d0 \uc758\ud574)\r\n\tprintf(&quot;CAlpha class=%s\\n&quot;,pObj1-&gt;GetRuntimeClass()-&gt;m_lpszClassName);\r\n\r\n\tdelete pObj1;\r\n\r\n#ifdef DEBUG\r\n\t\/\/cmd\r\n\tchar e;\r\n\tscanf(&quot;%c&quot;,&amp;e);\r\n#endif\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=174"}],"version-history":[{"count":1,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}