{"id":3208,"date":"2023-03-06T06:16:00","date_gmt":"2023-03-05T21:16:00","guid":{"rendered":"http:\/\/43.203.250.216\/?p=3208"},"modified":"2023-03-05T18:18:02","modified_gmt":"2023-03-05T09:18:02","slug":"c-template-%ec%84%a0%ec%96%b8%ea%b3%bc-%ea%b5%ac%ed%98%84%ec%9d%84-%ec%84%9c%eb%a1%9c-%eb%8b%a4%eb%a5%b8-%ed%8c%8c%ec%9d%bc%ec%97%90-%eb%82%98%eb%88%8c-%ec%88%98-%ec%97%86%eb%8b%a4","status":"publish","type":"post","link":"https:\/\/litcoder.com\/?p=3208","title":{"rendered":"C++ template \uc120\uc5b8\uacfc \uad6c\ud604\uc744 \uc11c\ub85c \ub2e4\ub978 \ud30c\uc77c\uc5d0 \ub098\ub20c \uc218 \uc5c6\ub2e4"},"content":{"rendered":"\n<p>\ucee4\uc2a4\ud140 Queue \ud074\ub798\uc2a4\ub97c \uc791\uc131\ud558\ub294\ub370 queue\uc758 item\uc740 \ucd94\ud6c4\uc5d0 \ubcc0\uacbd \ub420 \uc218 \uc788\uc73c\ubbc0\ub85c \ud15c\ud50c\ub9bf\uc73c\ub85c \uc791\uc131\ud558\uace0\uc790 \ud55c\ub2e4. Queue class\ub97c header\uc5d0 \uc815\uc758\ud558\uace0 \uad6c\ud604\uc744 cpp \ud30c\uc77c\uc5d0 \uc791\uc131\ud574 \uc900\ub2e4\uc74c main \ud568\uc218\uc5d0\uc11c \ub2e4\uc74c\uacfc \uac19\uc774 queue\ub97c \uc0dd\uc131\ud558\uace0 \ucef4\ud30c\uc77c\uc744 \uc2dc\ub3c4\ud55c\ub2e4.<\/p>\n\n\n\n<p>\ub2e4\uc74c\uc740 \ud574\ub2f9 template\uc744 \uc0ac\uc6a9\ud558\ub294 caller(main \ud568\uc218)\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\n\/\/ C++ template instantiation test.\n\/\/\n\/\/                                             - litcoder\n\n#include &lt;iostream>\n#include \"queue.h\"\n\nusing namespace std;\nint main() {\n    \/\/ Create an integer type queue.\n    queue&lt;int> q;\n\n    \/\/ Push elements from the queue.\n    q.push(0);\n    q.push(1);\n    q.push(2);\n\n    \/\/ Pop and print all elements.\n    while (! q.empty()) {\n        cout &lt;&lt; \"Popped: \" &lt;&lt; q.pop() &lt;&lt; endl;\n    }\n\n    return 0;\n}<\/pre>\n\n\n\n<p>\ud558\uc9c0\ub9cc \ubcc4 \ubb38\uc81c \uc5c6\uc744\uac83\uc774\ub77c\ub294 \uc0dd\uac01\uacfc \ub2ec\ub9ac \uc548\ud0c0\uae5d\uac8c\ub3c4 \ube4c\ub4dc\ub294 \uc2e4\ud328\ud55c\ub2e4. \uacf5\ub4e4\uc5ec\uc11c \ub9cc\ub4e0 method\uac00 \ub9c1\ucee4\uc5d0 \uc758\ud574 \ud558\ub098\ub3c4 \ube60\uc9d0\uc5c6\uc774 &#8220;undefined reference&#8221; \uc624\ub958\ub97c \ubc49\uc73c\uba74\uc11c \uc2e4\ud328\ud55c\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ make\ng++  -g -Wall  -c -o queue.o queue.cpp\ng++  -g -Wall  -c -o main.o main.cpp\ng++ -o qtest queue.o main.o\n\/usr\/bin\/ld: main.o: in function `main':\n\/home\/litcoder\/Downloads\/cpptemplate\/main.cpp:12: undefined reference to `queue&lt;int>::queue()'\n\/usr\/bin\/ld: \/home\/litcoder\/cpptemplate\/main.cpp:15: undefined reference to `queue&lt;int>::push(int)'\n\/usr\/bin\/ld: \/home\/litcoder\/cpptemplate\/main.cpp:16: undefined reference to `queue&lt;int>::push(int)'\n\/usr\/bin\/ld: \/home\/litcoder\/cpptemplate\/main.cpp:17: undefined reference to `queue&lt;int>::push(int)'\n\/usr\/bin\/ld: \/home\/litcoder\/cpptemplate\/main.cpp:21: undefined reference to `queue&lt;int>::pop()'\n\/usr\/bin\/ld: \/home\/litcoder\/cpptemplate\/main.cpp:20: undefined reference to `queue&lt;int>::empty()'\n\/usr\/bin\/ld: \/home\/litcoder\/cpptemplate\/main.cpp:25: undefined reference to `queue&lt;int>::~queue()'\n\/usr\/bin\/ld: \/home\/litcoder\/cpptemplate\/main.cpp:25: undefined reference to `queue&lt;int>::~queue()'\ncollect2: error: ld returned 1 exit status\nmake: *** [Makefile:7: qtest] Error 1\n<\/pre>\n\n\n\n<p>\uc774 \ubb38\uc81c\uc5d0 \ub300\ud55c \ud574\uacb0\ucc45\uc740 \uc0dd\uac01\ubcf4\ub2e4 \uac04\ub2e8\ud55c\ub370, cpp\ud30c\uc77c\uc5d0 \ub530\ub85c \ubd84\ub9ac\ud588\ub358 \uad6c\ud604 \ubd80\ubd84\uc744 \uc120\uc5b8\ub4e4\uacfc \ud568\uaed8 header file\uc5d0 \ub450\ub294 \uac83\uc774\ub2e4. (\ud574\uce58\uc6e0\ub098?)<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ make\ng++  -g -Wall  -c -o queue.o queue.cpp\ng++  -g -Wall  -c -o main.o main.cpp\ng++ -o qtest queue.o main.o\n$ .\/qtest\nPopped: 0\nPopped: 1\nPopped: 2<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\uc65c undefined reference \uc624\ub958\uac00 \ub0ac\uc744\uae4c?<\/h2>\n\n\n\n<p>Queue.o\uac00 \ube4c\ub4dc\ub410\uc73c\ub2c8 \uac70\uae30 \ubcf4\uba74 \ubd84\uba85\ud788 \uc800 method\ub4e4\uc774 \uc120\uc5b8\ub418\uc5b4 \uc788\uc744\ud150\ub370 \ub9d0\uc774\ub2e4. \ube4c\ub4dc\ub41c symbol\ub4e4\uc744 \uc0b4\ud3b4\ubcf4\uc790,<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ objdump -t .\/queue.o\n\n.\/queue.o:     file format elf64-x86-64\n\nSYMBOL TABLE:\n0000000000000000 l    df *ABS*\t0000000000000000 queue.cpp\n<\/pre>\n\n\n\n<p>O.O \uc5c6\ub2e4. \uc544\ubb34\uac83\ub3c4. queue.o\ub294 \uc544\ubb34 symbol\uc774 \uc5c6\ub294 \ube48 \ud30c\uc77c\uc774\uc5c8\ub2e4.<\/p>\n\n\n\n<p>\uc55e\uc11c \ud574\uacb0\ub410\ub2e4\uace0 \ud588\ub358 header\uc5d0\uc11c template \uc120\uc5b8\uacfc \uad6c\ud604\uc744 \ubaa8\ub450 \uc218\ud589\ud558\ub294 \uacbd\uc6b0\uc5d0\ub3c4 queue.o\uc758 symbol table\uc774 \ube44\uc5b4 \uc788\ub294\uac83\uc740 \ub9c8\ucc2c\uac00\uc9c0 \uc774\uc9c0\ub9cc, \uc774 \uacbd\uc6b0, caller\uc778 main.o\uc5d0\ub294 template\uc774 \uc2e4\uc81c \uc0ac\uc6a9\ud558\ub294 type\uc5d0 binding\ub418\uc5b4 embed\ub418\uc5b4 \uc788\ub2e4. main.o\uc758 symbol\ub4e4\uc744 \uc0b4\ud3b4\ubcf4\uba74 \ub2e4\uc74c\uacfc \uac19\uc774 mangle\ub41c symbol\ub4e4\uc744 \ubcfc \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ objdump -t .\/main.o\n\n.\/main.o:     file format elf64-x86-64\n\nSYMBOL TABLE:\n0000000000000000 l    df *ABS*\t0000000000000000 main.cpp\n...\n0000000000000000  w    F .text._ZN5queueIiEC2Ev\t0000000000000048 _ZN5queueIiEC1Ev\n0000000000000000  w    F .text._ZN5queueIiE4pushEi\t000000000000003f _ZN5queueIiE4pushEi\n...<\/pre>\n\n\n\n<p>\ucc38\uace0\ub85c, C++ symbol\uc758 type\uc740 <a href=\"http:\/\/demangler.com\/\">demangler<\/a>\ub97c \uc774\uc6a9\ud558\uba74 \ubcfc \uc218 \uc788\ub294\ub370, demangle\ud55c \uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">_ZN5queueIiEC2Ev -> queue&lt;int>::queue()\n_ZN5queueIiE4pushEi -> queue&lt;int>::push(int)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\uacb0\ub860<\/h2>\n\n\n\n<p>C++ template\uc740 \ube4c\ub4dc\ud558\ub294 \uc2dc\uc810\uc5d0\uc11c \uc5b4\ub5a4 data type\uc73c\ub85c binding\ub420 \uc9c0 \uc54c \uc218 \uc5c6\uae30 \ub54c\ubb38\uc5d0 \uad6c\ud604 \ubd80\ubd84\uc744 \ubcc4\ub3c4\uc758 \ud30c\uc77c\ub85c \ub9cc\ub4e4\uc5b4 \ubd24\uc790 \uc544\ubb34 \uac83\ub3c4 \ube4c\ub4dc \ub418\uc9c0 \uc54a\ub294\ub2e4. Header file\uc5d0 \uc120\uc5b8\uacfc \uad6c\ud604\uc744 \ud568\uaed8 \ub450\uace0 \uc774 template\uc744 \uc0ac\uc6a9\ud558\ub294 code\uac00 \uc774\ub97c include\ud558\uc5ec \uc5b4\ub5a4 data type\uc73c\ub85c binding\ub420 \uc9c0 \uacb0\uc815\ud574 \uc8fc\uba74 \uadf8\ub54c\uc11c\uc57c \uc2e4\uc81c symbol\uc774 caller module\uc5d0 \ud3ec\ud568\ub41c\ub2e4.<\/p>\n\n\n\n<p>\uc989, template\uc744 \uc120\uc5b8\uacfc \uad6c\ud604\uc73c\ub85c \ub098\ub204\uc5b4\uc11c \ub530\ub85c \ube4c\ub4dc\ud558\ub294 \uac83\uc740 \ubd88\uac00\ub2a5\ud560 \ubfd0\ub354\ub7ec \uc758\ubbf8\ub3c4 \uc5c6\uc73c\ub2c8 include\ub420 \ud558\ub098\uc758 \ud30c\uc77c(\uc8fc\ub85c header)\uc5d0 \ub123\uc5b4\uc11c \uc120\uc5b8\uacfc \uad6c\ud604\uc744 \ud569\uccd0\ub450\ub294\uac8c \uac00\uc7a5 \uc88b\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ucee4\uc2a4\ud140 Queue \ud074\ub798\uc2a4\ub97c \uc791\uc131\ud558\ub294\ub370 queue\uc758 item\uc740 \ucd94\ud6c4\uc5d0 \ubcc0\uacbd \ub420 \uc218 \uc788\uc73c\ubbc0\ub85c \ud15c\ud50c\ub9bf\uc73c\ub85c \uc791\uc131\ud558\uace0\uc790 \ud55c\ub2e4. Queue class\ub97c header\uc5d0 \uc815\uc758\ud558\uace0 \uad6c\ud604\uc744 cpp \ud30c\uc77c\uc5d0 \uc791\uc131\ud574 \uc900\ub2e4\uc74c main \ud568\uc218\uc5d0\uc11c \ub2e4\uc74c\uacfc \uac19\uc774 queue\ub97c \uc0dd\uc131\ud558\uace0 \ucef4\ud30c\uc77c\uc744 \uc2dc\ub3c4\ud55c\ub2e4. \ub2e4\uc74c\uc740 \ud574\ub2f9 template\uc744 \uc0ac\uc6a9\ud558\ub294 caller(main \ud568\uc218)\uc774\ub2e4. \ud558\uc9c0\ub9cc \ubcc4 \ubb38\uc81c \uc5c6\uc744\uac83\uc774\ub77c\ub294 \uc0dd\uac01\uacfc \ub2ec\ub9ac \uc548\ud0c0\uae5d\uac8c\ub3c4 \ube4c\ub4dc\ub294 \uc2e4\ud328\ud55c\ub2e4. \uacf5\ub4e4\uc5ec\uc11c \ub9cc\ub4e0 method\uac00 \ub9c1\ucee4\uc5d0 \uc758\ud574 \ud558\ub098\ub3c4 \ube60\uc9d0\uc5c6\uc774 &#8220;undefined reference&#8221; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[247,311,310],"class_list":["post-3208","post","type-post","status-publish","format-standard","hentry","category-programming","tag-c","tag-demangle","tag-template"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts\/3208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3208"}],"version-history":[{"count":8,"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts\/3208\/revisions"}],"predecessor-version":[{"id":3216,"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts\/3208\/revisions\/3216"}],"wp:attachment":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}