{"id":1567,"date":"2022-08-30T15:17:36","date_gmt":"2022-08-30T15:17:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/undefined-reference-to-void-sortswapintint-int-int-duplicate-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:36","modified_gmt":"2022-08-30T15:17:36","slug":"undefined-reference-to-void-sortswapintint-int-int-duplicate-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/undefined-reference-to-void-sortswapintint-int-int-duplicate-collection-of-common-programming-errors\/","title":{"rendered":"undefined reference to `void sort::swap&lt;int&gt;(int*, int, int)&#39; [duplicate]-Collection of common programming errors"},"content":{"rendered":"<blockquote>\n<p><strong>Possible Duplicate:<\/strong><br \/>\nWhy can templates only be implemented in the header file?<\/p>\n<\/blockquote>\n<p>Here&#8217;s my make file:<\/p>\n<pre><code>\n#!\/usr\/bin\/make -f\ncompiler = g++\ncompiler_flags = -Wall -I \/usr\/include\/c++\/4.5\ndebug_flags = -D DEBUG -g\nbinary_filename = sort_testing.bin\n\nall: clean release\n\nrelease: \n    $(compiler) $(compiler_flags) main.cpp sort.o -o $(binary_filename)\ndebug: sort.o \n    $(compiler) $(debug_flags) $(compiler_flags) main.cpp sort.o -o $(binary_filename)\nrun: \n    .\/$(binary_filename)\nclean: \n    rm -f *.o $(binary_filename)\nsort.o: \n    $(compiler) $(debug_flags) $(compiler_flags) -c sort.cpp\n<\/code><\/pre>\n<p>Here are my C++ Files:<\/p>\n<pre><code>\n\/\/ sort.hpp\n#ifndef SORT_H\n#define SORT_H\n\nnamespace sort{\n    template void swap(T*,int,int);\n}\n\n#endif\n\n\/\/ sort.cpp\n#include \"sort.hpp\"\n\nnamespace sort{\n    template\n    void swap(T* items, int index_a, int index_b){\n        T t = items[index_a];\n        items[index_a] = items[index_b];\n        items[index_b] = t;\n    }\n}\n\n\/\/ main.cpp\n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n#include \"sort.hpp\"\nusing namespace sort;\n\n#define NUM_INTS 5\n\nint main(int argc, char** argv){\n    try{\n        cout<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-27 11:52:18. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Possible Duplicate: Why can templates only be implemented in the header file? Here&#8217;s my make file: #!\/usr\/bin\/make -f compiler = g++ compiler_flags = -Wall -I \/usr\/include\/c++\/4.5 debug_flags = -D DEBUG -g binary_filename = sort_testing.bin all: clean release release: $(compiler) $(compiler_flags) main.cpp sort.o -o $(binary_filename) debug: sort.o $(compiler) $(debug_flags) $(compiler_flags) main.cpp sort.o -o $(binary_filename) run: .\/$(binary_filename) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1567","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1567"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1567\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}