{"id":152,"date":"2014-06-04T01:13:48","date_gmt":"2014-06-03T16:13:48","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=152"},"modified":"2019-06-27T10:41:03","modified_gmt":"2019-06-27T01:41:03","slug":"%eb%b3%b5%ec%82%ac%ec%83%9d%ec%84%b1%ec%9e%90-operator","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=152","title":{"rendered":"\ubcf5\uc0ac\uc0dd\uc131\uc790 operator"},"content":{"rendered":"\n<pre class=\"lang:c++ decode:true \" >#include \"stdafx.h\"\r\n#include &lt;string.h&gt;\r\n#include &lt;conio.h&gt;\r\n\r\n#define DEBUG\r\n\r\nclass CStr{\r\n    char* str;\r\npublic:\r\n\tCStr(char *s=\"\"){\r\n\t\tstr = new char[strlen(s)+1];\r\n\t\tstrcpy(str,s);\r\n\t\tprintf(\"construction\\n\");\r\n\t}\r\n\tCStr(const CStr &amp;s){\r\n\t\tstr = new char[strlen(s.Get())+1];\r\n\t\tstrcpy(str,s.Get());\/\/const \uac1d\uccb4\ub294 const \uba64\ubc84 \ud568\uc218\ub9cc\uc744 \ud638\ucd9c\ud560 \uc218 \uc788\ub2e4.\r\n\t\tprintf(\"construction\\n\");\r\n\t}\r\n\t~CStr() {\r\n\t\tdelete[] str;\r\n\t\tprintf(\"destructor\\n\");\r\n\t}\r\n\tchar* Get() const{\r\n\t\treturn str;\r\n\t}\r\n\tvoid Print() {printf(\"%s\\n\", str);}\r\n\r\n\tCStr&amp; operator=(CStr &amp;s){\r\n\t\tdelete[] str;\r\n\t\tstr=new char[strlen(s.Get())+1];\r\n\t\tstrcpy(str,s.Get());\r\n\t\tprintf(\"=operator\\r\\n\");\r\n\t\treturn *this;\r\n\t}\r\n};\r\n\r\nvoid f(CStr s){\r\n\ts.Print();\r\n}\r\n\r\nvoid main()\r\n{\r\n\tCStr s(\"hello\"),t(\"world\");\r\n\tCStr u=s;\/\/3. \uac1d\uccb4\uc758 \uc120\uc5b8\uc5d0 \uc0ac\uc6a9\ub41c \ub300\uc785 \uc5f0\uc0b0\uc790\r\n\tf(u);\/\/1. \ud568\uc218\uc758 \ud30c\ub77c\ubbf8\ud130\ub85c \uac1d\uccb4\ub97c \uc804\ub2ec\r\n\ts=t;\/\/*\uac1d\uccb4\uac04\uc758 \ub300\uc785\ubb38\uc740 \ubcf5\uc0ac \uc0dd\uc131\uc790\ub97c \ud638\ucd9c\ud558\uc9c0 \uc54a\ub294\ub2e4.\r\n\t\/\/operator= \ud638\ucd9c\r\n\ts.Print();\r\n\r\n#ifdef DEBUG\r\n\t\/\/cmd\r\n\tchar c;\r\n\tscanf(\"%c\",&amp;c);\r\n#endif\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include &#8220;stdafx.h&#8221; #include &lt;string.h&gt; #include &lt;conio.h&gt; #define DEBUG class CStr{ char* str; public: CStr(char *s=&#8221;&#8221;){ str = new char[strlen(s)+1]; strcpy(str,s); printf(&#8220;construction\\n&#8221;); } CStr(const CStr &amp;s){ str = new char[strlen(s.Get())+1]; strcpy(str,s.Get());\/\/const \uac1d\uccb4\ub294 const \uba64\ubc84 \ud568\uc218\ub9cc\uc744 \ud638\ucd9c\ud560 \uc218 \uc788\ub2e4. printf(&#8220;construction\\n&#8221;); } ~CStr() { delete[] str; printf(&#8220;destructor\\n&#8221;); } char* Get() const{ return str; } void Print() {printf(&#8220;%s\\n&#8221;, str);}\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=152\">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-152","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\/152","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=152"}],"version-history":[{"count":2,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions\/539"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}