{"id":184,"date":"2014-06-08T19:32:12","date_gmt":"2014-06-08T10:32:12","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=184"},"modified":"2023-01-27T10:12:13","modified_gmt":"2023-01-27T01:12:13","slug":"%ec%8b%b1%ea%b8%80%ed%86%a4-%ed%8c%a8%ed%84%b4","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=184","title":{"rendered":"\uc2f1\uae00\ud1a4 \ud328\ud134"},"content":{"rendered":"<pre class=\"lang:c++ decode:true \">#include&lt;stdio.h&gt;\n#include&lt;assert.h&gt;\n#include \"vector\"\n\n#define AfxGetApp() KSingleton&lt;CWinApp&gt;::GetSingleton()\n#define DEBUG\n\ntemplate&lt;typename T&gt;\nclass KSingleton\n{\nprivate:\n    static T* ms_pSingleton;\npublic:\n\tKSingleton()\n\t{\n\t\tassert(NULL == KSingleton&lt;T&gt;::ms_pSingleton);\n\t\tKSingleton&lt;T&gt;::ms_pSingleton = (T*)this;\n\t}\n\t~KSingleton()\n\t{\n\t\tKSingleton&lt;T&gt;::ms_pSingleton =NULL;\n\t}\n\tstatic T* GetSingleton()\n\t{\n\t\treturn ms_pSingleton;\n\t}\n};\n\n\/*static*\/ template&lt;typename T&gt; T* KSingleton&lt;T&gt;::ms_pSingleton = NULL;\nclass CWinApp : public KSingleton&lt;CWinApp&gt;\n{\npublic:\n\tvoid Print()\n\t{\n\t\tprintf(\"hello\\n\");\n\t}\n};\n\nCWinApp theApp;\n\nvoid main()\n{\n\t\/\/KSingleton&lt;CWinApp&gt;::GetSingleton()-&gt;Print(); \/\/\uc704\uc5d0\uc11c \uba54\ud06c\ub85c \uc801\uc6a9\n\tAfxGetApp()-&gt;Print();\n\n\t#ifdef DEBUG\n\t\/\/cmd\n\tchar e;\n\tscanf(\"%c\",&amp;e);\n#endif\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include&lt;stdio.h&gt; #include&lt;assert.h&gt; #include &#8220;vector&#8221; #define AfxGetApp() KSingleton&lt;CWinApp&gt;::GetSingleton() #define DEBUG template&lt;typename T&gt; class KSingleton { private: static T* ms_pSingleton; public: KSingleton() { assert(NULL == KSingleton&lt;T&gt;::ms_pSingleton); KSingleton&lt;T&gt;::ms_pSingleton = (T*)this; } ~KSingleton() { KSingleton&lt;T&gt;::ms_pSingleton =NULL; } static T* GetSingleton() { return ms_pSingleton; } }; \/*static*\/ template&lt;typename T&gt; T* KSingleton&lt;T&gt;::ms_pSingleton = NULL; class CWinApp : public KSingleton&lt;CWinApp&gt; { public:\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=184\">Read More &raquo;<\/a><\/span><\/p>\n","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-184","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\/184","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=184"}],"version-history":[{"count":4,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":855,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions\/855"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}