Im reading c++ primer plus and having some issues understanding how implicit instantiation works. I havent learned classes yet, so I am just dealing with functions. I think I understand the basics of implicit instantiation (function templates) but I just dont understand explicit instantiation. I have below a function that uses a template, can someone show me how a function like this would be written if it used a explicit instantiation. You can change the way it works, but just keep it simple. I would really be appreciative. This will help me understand the syntax, and how it is used.
2 #include <iostream>
3
4 template <typename T>
5 void show(T,T);
6
7
8 int main()
9 {
10 int a = 10, b = 12;
11 char c = 'x', d = 'y';
12
13 show(a,b);
14 show(c,d);
15
16 return 0;
17 }
18
19 template <typename T>
20 void show(T a, T b )
21 {
22 std::cout << "I used the int version " << a << " " << b << "\n";
23 }
Just do a
Show<int>(c, d)Notice that I’ve explicitly instantiated theintversion, but passed thecharparameters. That’s (a rather simple take on) explicit instantiation, but you might be actually referring to explicit specialization.