关于模板的一段程序

C++语言 码拜 8年前 (2016-05-08) 814次浏览
模板类的第三个参数也是个模板类,但是为什么是
template<class>
而不是
template<class T> 关于模板的一段程序
解决方案

10

原因是其它地方没有用到那个参数,不需要写名字,就跟h函数声明中的参数可以不写名字一样。

10

可写可不写。

10

模板的模板参数(template template parameter)
这名字挺绕的,而且用之前要三思这东西能否真的能达到预期的效果,二十年前标准库差点要使用这东西,后来发现它的功能不能完全满足需求

10

模板模板参数
LimitFunc 是 有一个模板参数的模板
MSDN 例子

// template_specifications3.cpp
#include <stdio.h>
template <class T> struct str1
{
   T t;
};
template <template<class A> class T> struct str2
{
    T<int> t;
};
int main()
{
    str2<str1> mystr2;
    mystr2.t.t = 5;
    printf_s("%d\n", mystr2.t.t);
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于模板的一段程序
喜欢 (0)
[1034331897@qq.com]
分享 (0)