Some notes about function template specialization:
- Explicit template specialization should be defined in namespace scope, and hence not inline within class body.
- Class templates can be partially specialized, but partial function template specialization is not allowed.
- The template parameter list after function name may be omitted, or some trailing arguments omitted. However, it is recommended to keep the <> pair.
- Template parameter list is part of signature for function templates and their specializations. Pay attention to the differences between function overloading and partial specialization.
// Suppose we have the function template template< typename T1, typename T2 > void func( T1 v1, T2 v2 ) { ... } // The following is considered as function template overloading and allowed template< typename T > void func( T v1, T v2 ) { ... } // The following is considered as partial specialization and not allowed template< typename T > void func< T, T >( T v1, T v2 ) { ... }
Function Signatures
Class Templates
No comments:
Post a Comment