当前位置:网站首页>类模板中可变参的逐步展开
类模板中可变参的逐步展开
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>
边栏推荐
- Crane: a new way of dealing with dictionary items and associated data
- Principle of printf indefinite length parameter
- 一次性彻底解决 Web 工程中文乱码问题
- Infiltration learning diary day20
- AXI总线
- Quick news: Huawei launched the Hongmeng developer competition; Tencent conference released the "Wanshi Ruyi" plan
- Prometheus 2.26.0 new features
- Hue new account error reporting solution
- POSIX AIO -- glibc 版本异步 IO 简介
- Privacy computing fat offline prediction
猜你喜欢
抖音实战~公开/私密短视频互转
Bluetooth health management device based on stm32
Number of printouts (solved by recursive method)
[WUSTCTF2020]girlfriend
关于接口测试自动化的总结与思考
ENSP cloud configuration
Hue new account error reporting solution
[weekly replay] the 81st biweekly match of leetcode
Cloud native (30) | kubernetes' app store Helm
基于STM32设计的蓝牙健康管理设备
随机推荐
关于接口测试自动化的总结与思考
Journal quotidien des questions (6)
一次性彻底解决 Web 工程中文乱码问题
创建Deployment后,无法创建Pod问题处理
Two TCP flow control problems
Cloud native (30) | kubernetes' app store Helm
局域网即时通讯软件应该怎么选择
scrapy
《预训练周刊》第51期:重构预训练、零样本自动微调、一键调用OPT
ENSP cloud configuration
使用bitnamiredis-sentinel部署Redis 哨兵模式
On the complexity of software development and the way to improve its efficiency
Full explanation of ThreadLocal source code (threadlocalmap)
防火墙基础之华为华三防火墙web页面登录
思考的角度的差异
What is low code for digital Nova? What is no code
7 killer JS lines of code
Good luck today
[WUSTCTF2020]girlfriend
Summary of redis master-slave replication principle