Specialized Partial C ++ Template Syntax

for the primary template:

template<typename A, typename B> class MyClass {...

with a specialization template, what is the difference between

template<typename A, typename B> class MyClass<int, float> {...

and

template<> class MyClass<int, float> {...
+3
source share
1 answer

template<typename A, typename B> class MyClass<int, float> {...not allowed. Indeed, if you specify formal parameters Aand B, your template should use them.

The second case is just normal: you say that you do specialization without "free" parameters.

Intermediate case may be

template<typename A> class MyClass<A, float> {...

which is again true: here you only fix the second parameter of the template.

: . . :

template<typename X, typename Y, typename Z> class MyClass<X*, Y(Z&)> {...

. " X, Y Z, MyClass X* Y(Z&), ". , .

+6

Source: https://habr.com/ru/post/1780329/


All Articles