How does specialization work with two templates? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How does specialization work with two templates?

21st Jul 2016, 5:18 PM
Aceitunarabe
Aceitunarabe - avatar
8 Answers
+ 1
There is none. In the example case I prefer typename since typename actually denominates what U and T are intended to be: any type you want (and in the example case it's int and char). If I would only pass classes, I would use the class keyword.
21st Jul 2016, 6:05 PM
Stefan
Stefan - avatar
+ 1
Btw, to name stuff clearly: U and T are template parameters and the template is the class A.
21st Jul 2016, 6:08 PM
Stefan
Stefan - avatar
0
You mean partial specialization?
21st Jul 2016, 5:40 PM
Stefan
Stefan - avatar
0
I mean, if I need to specialize a class which uses 2 different templates, let's say T and U, if I need to make a special behaviour for when U is a char, what'll be the syntaxe?
21st Jul 2016, 5:43 PM
Aceitunarabe
Aceitunarabe - avatar
0
Btw, some older compilers have problems with the partial template specialization. In other words: it doesn't work, even though it's in the standard they try to implement.
21st Jul 2016, 5:54 PM
Stefan
Stefan - avatar
0
Thanks! And BTW, what is the difference between naming templates class or typename?
21st Jul 2016, 6:01 PM
Aceitunarabe
Aceitunarabe - avatar
0
Thx for the precision :)
21st Jul 2016, 6:14 PM
Aceitunarabe
Aceitunarabe - avatar