当前位置:网站首页>类模板中可变参的逐步展开
类模板中可变参的逐步展开
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>
边栏推荐
- 云原生(三十) | Kubernetes篇之应用商店-Helm
- JSON. Stringify usage
- Axi bus
- 清楚的自我定位
- Cloud native (30) | kubernetes' app store Helm
- 7 killer JS lines of code
- With the advent of the era of Internet of everything, Ruijie released a scenario based wireless zero roaming scheme
- 外包2年的我终于上岸了!记录我的字节跳动3轮面试,希望帮助到大家!
- 【Acwing】第57场周赛 题解
- 这是什么空调?
猜你喜欢

ensp云朵配置

Today's sleep quality record 78 points

AXI总线

After 2 years of outsourcing, I finally landed! Record my ByteDance 3 rounds of interviews, hope to help you!

CMOS级电路分析
![[acwing] explanation of the 57th weekly competition](/img/ef/be89606b0e7fffac08280db0a73781.gif)
[acwing] explanation of the 57th weekly competition

High efficiency exponentiation

每日刷題記錄 (六)

Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices

Good luck today
随机推荐
高效率取幂运算
[weekly replay] the 81st biweekly match of leetcode
IJCAI 2022 | 用一行代码大幅提升零样本学习方法效果,南京理工&牛津提出即插即用分类器模块
Using FRP tool to realize intranet penetration
手把手教你搭一个永久运行的个人服务器!
PLM还能怎么用?
Cesium实现卫星在轨绕行
创建Deployment后,无法创建Pod问题处理
快速搭建一个自己的访问国外网站,搭建ss并开启bbr快速上网
Realization of hospital medical record management system based on JSP
再懂已是曲中人
Deeply convinced plan X - system foundation summary
A method to realize automatic renaming of pictures uploaded by WordPress
深入理解位运算
深信服X计划-系统基础总结
防火墙基础之华为华三防火墙web页面登录
What is low code for digital Nova? What is no code
[problem solving] which nodes are run in tensorflow?
同花顺能开户炒股吗?安全吗?
动态规划