当前位置:网站首页>Step by step expansion of variable parameters in class templates
Step by step expansion of variable parameters in class templates
2022-06-27 13:44:00 【Hair like snow ty】
1.myclasst<Args…> Inherit
template<typename...Args>
class myclasst
{
public:
myclasst()
{
cout << "myclasst::myclasst() Yes , Variable parameters :" << sizeof...(Args) << endl;
}
};
template<typename...Args>
class myclasst2 :public myclasst<Args...>
{
public:
myclasst2()
{
cout << "myclasst2::myclasst2() Yes , Variable parameters :" << sizeof...(Args) << endl;
}
};
int main()
{
myclasst2<double, float, int> tmpobj;
system("pause");
return 0;
}
result :
From the running results, it can be seen that the myclasst2<double,float,int> class .
2.myclasst… Inherit
Now put it another way , as follows :
template<typename...Args>
class myclasst2 :public myclasst<Args>...
{
public:
myclasst2()
{
cout << "myclasst2::myclasst2() Yes , Variable parameters :" << sizeof...(Args) << endl;
}
};
result :
It's modified here myclasst2 The inherited parent class , Turned out to be myclasst<Args...>
, Now the … Put it outside the right angle bracket , Change into myclasst<Args>...
(1) without doubt , It will be instantiated myclasst2<double,float,int> class , because tmpobj Is the object belonging to this class ;
(2)Args It represents a package type , Here the package type is double,float,int common 3 A type of ; and myclasst<Args>...
After instantiation, this expression represents 3 Classes , Namely myclasst<double>,myclasst<float>,myclasst<int>
(3) So in this case myclasst2<double,float,int> The parent class of class actually has 3 individual . So for statements :
class myclasst2:public myclasst<Args>...
It's actually equivalent to :
class myclasst2:public myclasst<double>,public myclasst<double>,public myclasst<int>
边栏推荐
- 线程同步之信号量
- Infiltration learning diary day20
- 力扣 第 81 场双周赛
- Number of printouts (solved by recursive method)
- 关于接口测试自动化的总结与思考
- 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
- CMOS level circuit analysis
- 万物互联时代到来,锐捷发布场景化无线零漫游方案
- 快速搭建一个自己的访问国外网站,搭建ss并开启bbr快速上网
- crane:字典项与关联数据处理的新思路
猜你喜欢
随机推荐
Cesium realizes satellite orbit detour
[problem solving] which nodes are run in tensorflow?
A statistical problem of shell script
力扣 第 81 场双周赛
IJCAI 2022 | 用一行代码大幅提升零样本学习方法效果,南京理工&牛津提出即插即用分类器模块
enable_if
Realization of hospital medical record management system based on JSP
Cesium实现卫星在轨绕行
[a complete human-computer interface program framework]
重读经典:《The Craft of Research(1)》
关于接口测试自动化的总结与思考
为什么 Oracle 云客户必须在Oracle Cloud 季度更新发布后自行测试?
招标公告:暨南大学附属第一医院Oracle数据库维保服务采购
my.ini文件配置
每日3题(2):检查二进制字符串字段
打印输出数(递归方法解决)
Pre training weekly issue 51: reconstruction pre training, zero sample automatic fine tuning, one click call opt
Crane: a new way of dealing with dictionary items and associated data
What else can PLM do?
Why must Oracle cloud customers self test after the release of Oracle cloud quarterly update?