KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm on a roll today. Here goes n00b question number 7: What's the difference between explicit specialization and just regular functions when you try to overload a template function? What's the appropriate situation to use the explicit specialization? I don't quite understand it: #include <iostream> template <typename s> void test(s var1); template <> void test<int>(int var1); int main(){ test(1); test(1.1); test("hello!!"); return 0; } template <typename s> void test(s var1){ std::cout << var1 << std::endl; } template <> void test<int>(int var1){ std::cout << "int " << var1 << std::endl; } As oppose to: #include <iostream> template <typename s> void test(s var1); void test(int var1); int main(){ test(1); test(1.1); test("hello!!"); return 0; } template <typename s> void test(s var1){ std::cout << var1 << std::endl; } void test(int var1){ std::cout << "int " << var1 << std::endl; }
Tags (comma-separated)
Save Edits
Cancel