当前位置:网站首页>类模板中可变参的逐步展开
类模板中可变参的逐步展开
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>
边栏推荐
- Different habits
- 爱可可AI前沿推介(6.27)
- Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices
- What is low code for digital Nova? What is no code
- What kind of air conditioner is this?
- Shell 简明教程
- Axi bus
- Cloud native (30) | kubernetes' app store Helm
- 关于接口测试自动化的总结与思考
- 云原生(三十) | Kubernetes篇之应用商店-Helm
猜你喜欢

Cesium realizes satellite orbit detour

Does Xinhua San still have to rely on ICT to realize its 100 billion enterprise dream?

基于STM32设计的蓝牙健康管理设备

基于 xml 配置文件的入门级 SSM 框架整合

硬件开发笔记(七): 硬件开发基本流程,制作一个USB转RS232的模块(六):创建0603封装并关联原理图元器件

【动态规划】—— 背包问题

Cesium实现卫星在轨绕行

打印输出数(递归方法解决)

Make learning pointer easier (1)

Teach you how to build a permanent personal server!
随机推荐
[WUSTCTF2020]girlfriend
Socket blocking and non blocking modes
这是什么空调?
Implementation of recruitment website based on SSM
手把手教你搭一个永久运行的个人服务器!
阿胖的操作记录
同花顺能开户炒股吗?安全吗?
昨天访问量破记录
Cloud native (30) | kubernetes' app store Helm
7 killer JS lines of code
Make learning pointer easier (2)
使用bitnamiredis-sentinel部署Redis 哨兵模式
IJCAI 2022 | greatly improve the effect of zero sample learning method with one line of code. Nanjing Institute of Technology & Oxford proposed the plug and play classifier module
打印输出数(递归方法解决)
With the advent of the era of Internet of everything, Ruijie released a scenario based wireless zero roaming scheme
Istio微服务治理网格流量管理核心资源控制器详解
Embedded development: embedded foundation callback function
A statistical problem of shell script
诗歌一首看看
Summary of basic usage of command line editor sed