{"id":1380,"date":"2007-06-22T01:32:00","date_gmt":"2007-06-22T01:32:00","guid":{"rendered":""},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T22:00:00","slug":"Jare","status":"publish","type":"post","link":"https:\/\/iguanademos.com\/Jare\/wp\/?p=1380","title":{"rendered":"Funky Visual Studio 2005 bug"},"content":{"rendered":"<p>I ran into this today with VS2005 SP1: if you define the body of a specialization of a template class&#8217; member function in a separate cpp file, the linker will barf:<\/p>\n<blockquote>\n<hr \/>\n<p><code>template&lt;class&nbsp;T&gt;&nbsp;struct&nbsp;A&nbsp;{&nbsp;void&nbsp;f()&nbsp;{}&nbsp;};<br \/>template&lt;&gt;&nbsp;void&nbsp;A&lt;int&gt;::f();&nbsp;\/\/&nbsp;body&nbsp;in&nbsp;a&nbsp;separate&nbsp;cpp<\/p>\n<p>void&nbsp;main()<br \/>{<br \/>&nbsp;&nbsp;A&lt;int&gt;&nbsp;a;<br \/>&nbsp;&nbsp;a.f();&nbsp;\/\/&nbsp;Linker&nbsp;complains&nbsp;that&nbsp;this&nbsp;function&nbsp;is&nbsp;undefined.<br \/>}<\/code><\/p>\n<hr \/>\n<\/blockquote>\n<p>You have to define the body in all source files (or at least one) that actually use the specialization of that function, normally in the header file:<\/p>\n<blockquote>\n<hr \/>\n<p><code>template&lt;class&nbsp;T&gt;&nbsp;struct&nbsp;A&nbsp;{&nbsp;void&nbsp;f()&nbsp;{}&nbsp;};<br \/>template&lt;&gt;&nbsp;void&nbsp;A&lt;int&gt;::f()&nbsp;{&nbsp;}<\/p>\n<p>void&nbsp;main()<br \/>{<br \/>&nbsp;&nbsp;A&lt;int&gt;&nbsp;a;<br \/>&nbsp;&nbsp;a.f();<br \/>}<\/code><\/p>\n<hr \/>\n<\/blockquote>\n<p>Not sure if I have explained correctly, but I hope you get the idea.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran into this today with VS2005 SP1: if you define the body of a specialization of a template class&#8217; member function in a separate cpp file, the linker will barf: template&lt;class&nbsp;T&gt;&nbsp;struct&nbsp;A&nbsp;{&nbsp;void&nbsp;f()&nbsp;{}&nbsp;};template&lt;&gt;&nbsp;void&nbsp;A&lt;int&gt;::f();&nbsp;\/\/&nbsp;body&nbsp;in&nbsp;a&nbsp;separate&nbsp;cpp void&nbsp;main(){&nbsp;&nbsp;A&lt;int&gt;&nbsp;a;&nbsp;&nbsp;a.f();&nbsp;\/\/&nbsp;Linker&nbsp;complains&nbsp;that&nbsp;this&nbsp;function&nbsp;is&nbsp;undefined.} You have to define the body in &hellip; <a href=\"https:\/\/iguanademos.com\/Jare\/wp\/?p=1380\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1380","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1380"}],"version-history":[{"count":0,"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1380\/revisions"}],"wp:attachment":[{"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iguanademos.com\/Jare\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}