C ++模板说明 [英] C++ Template clarification
本文介绍了C ++模板说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以请我解释下面给出的声明的含义吗?
Can anyone please explain me the meaning of the statement given below
template <typename T, int N>
char (&array(T(&)[N]))[N];
推荐答案
它是显式的模板专业化.
模板专门化有两种类型
1.明确
Its a explicit template specialization.
There are two types of template specialization
1. Explicit
template<> void sort<char*>(Array<char*>&);
2.部分
2. Partial
template<class T1, class T2, int I>
class A { };
我们可以专门针对T2为T1 *的情况进行专门设置:
We can specialize this for the case when T2 is a T1*:
template<class T, int I>
class A<T, T*, I> { };
或对于T1是任何指针的情况:
Or for the case when T1 is any pointer:
template<class T1, class T2, int I>
class A<T1*, T2, I> { };
或者对于T1为int且T2为任意指针且I为5的情况:
Or for the case when T1 is int and T2 is any pointer and I is 5:
template<class T>
class A<int, T*, 5> { };
或对于T2是任何指针的情况:
Or for the case when T2 is any pointer:
template<class T1, class T2, int I>
class A<T1, T2*, I> { };
声明2至5声明了主模板的部分专业化.
[edit]已修复,因此所有尖括号均显示[/edit]
[edit:rjm]添加了< pre>标签[/edit]
Declarations 2 to 5 declare partial specializations of the primary template.
[edit]Fixed so that all the angle brackets show[/edit]
[edit:rjm]added <pre> tags[/edit]
这篇关于C ++模板说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文