当前位置:网站首页>类模板中可变参的逐步展开
类模板中可变参的逐步展开
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>
边栏推荐
- ENSP cloud configuration
- Hue new account error reporting solution
- buuctf misc 百里挑一
- 防火墙基础之华为华三防火墙web页面登录
- 快讯:华为启动鸿蒙开发者大赛;腾讯会议发布“万室如意”计划
- After 2 years of outsourcing, I finally landed! Record my ByteDance 3 rounds of interviews, hope to help you!
- 微服务如何拆分
- 打印输出数(递归方法解决)
- 再懂已是曲中人
- Embedded development: embedded foundation callback function
猜你喜欢

Size end byte order

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

Make learning pointer easier (2)

Ali an interview question: use two threads to output letters and numbers alternately

Cesium realizes satellite orbit detour

High efficiency exponentiation
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (III)](/img/ce/b58e436e739a96b3ba6d2d33cf8675.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (III)

Record number of visits yesterday

Full explanation of ThreadLocal source code (threadlocalmap)

AXI總線
随机推荐
云原生(三十) | Kubernetes篇之应用商店-Helm
Using FRP tool to realize intranet penetration
How to use 200 lines of code to implement Scala's Object Converter
高效率取幂运算
与生活握手言和
数字化新星何为低代码?何为无代码
抖音实战~公开/私密短视频互转
Teach you how to build a permanent personal server!
[problem solving] which nodes are run in tensorflow?
手把手教你搭一个永久运行的个人服务器!
Istio微服务治理网格流量管理核心资源控制器详解
Implementation of recruitment website based on SSM
昨天访问量破记录
Deploy redis sentinel mode using bitnamiredis Sentinel
Principle of printf indefinite length parameter
Kotlin函数使用示例教程
How to split microservices
【Acwing】第57场周赛 题解
Different habits
嵌入式开发:嵌入式基础——回调函数