当前位置:网站首页>类模板中可变参的逐步展开
类模板中可变参的逐步展开
2022-06-27 13:17:00 【发如雪-ty】
1.myclasst<Args…>继承
template<typename...Args>
class myclasst
{
public:
myclasst()
{
cout << "myclasst::myclasst()执行了,可变参数:" << sizeof...(Args) << endl;
}
};
template<typename...Args>
class myclasst2 :public myclasst<Args...>
{
public:
myclasst2()
{
cout << "myclasst2::myclasst2()执行了,可变参数:" << sizeof...(Args) << endl;
}
};
int main()
{
myclasst2<double, float, int> tmpobj;
system("pause");
return 0;
}
结果:
从运行结果可以看出实例化出了myclasst2<double,float,int>类。
2.myclasst…继承
现在换一种写法,如下:
template<typename...Args>
class myclasst2 :public myclasst<Args>...
{
public:
myclasst2()
{
cout << "myclasst2::myclasst2()执行了,可变参数:" << sizeof...(Args) << endl;
}
};
结果:
这里修改了myclasst2所继承的父类,原来是myclasst<Args...>,现在把…放到右尖括号之外,变为了myclasst<Args>...
(1)毫无疑问,肯定会实例化出myclasst2<double,float,int>类,因为tmpobj就是属于该类的对象;
(2)Args代表的是一包类型,在这里这一包类型为double,float,int共3个类型;而myclasst<Args>...这种写法实例化后代表3个类,分别是myclasst<double>,myclasst<float>,myclasst<int>
(3)所以这种情况下myclasst2<double,float,int>类的父类实际有3个。所以对于语句:
class myclasst2:public myclasst<Args>...
实际等价于:
class myclasst2:public myclasst<double>,public myclasst<double>,public myclasst<int>
边栏推荐
- After the deployment is created, the pod problem handling cannot be created
- Cesium实现卫星在轨绕行
- 【第27天】给定一个整数 n ,打印出1到n的全排列 | 全排列模板
- 与生活握手言和
- 每日刷题记录 (六)
- Number of printouts (solved by recursive method)
- 思考的角度的差异
- POSIX AIO -- Introduction to glibc version asynchronous IO
- MySQL locking mechanism and four isolation levels
- A statistical problem of shell script
猜你喜欢
随机推荐
【周赛复盘】LeetCode第81场双周赛
jvm 性能调优、监控工具 -- jps、jstack、jmap、jhat、jstat、hprof
Intranet learning notes (8)
今日睡眠质量记录78分
IJCAI 2022 | 用一行代码大幅提升零样本学习方法效果,南京理工&牛津提出即插即用分类器模块
打印输出数(递归方法解决)
mysql 锁机制与四种隔离级别
Awk concise tutorial
防火墙基础之华为华三防火墙web页面登录
微服务如何拆分
How to use 200 lines of code to implement Scala's Object Converter
ZABBIX supports nail alarm
Prometheus 2.26.0 new features
隐私计算FATE-离线预测
[day 27] given an integer n, print out the full permutation from 1 to n | Full Permutation template
Can flush open an account for stock trading? Is it safe?
7 killer JS lines of code
实现WordPress上传图片自动重命名的方法
手把手教你搭一个永久运行的个人服务器!
深入理解位运算

![[dynamic programming] - Knapsack Problem](/img/27/c48284f15e3f80305d7ce7c02d4378.png)




![[medical segmentation] unet3+](/img/93/1e9728a3dbebbf3bd9ce015552ce7a.jpg)


