#include<iostream>
using namespace std;
/*args都是类类型*/
template<typename ...args>
class A : public args... {
//或者class A : args...
public:
A()
{
printf("this = %p\n", this);
}
};
class one {
public:
one()
{
printf("this = %p\n", this);
}
};
class two {
public:
two()
{
printf("this = %p\n", this);
}
};
class three {
public:
three()
{
printf("this = %p\n", this);
}
};
int main(int argc, char* argv[])
{
A<one, two, three> obj;
/*
A<one, two, three>相当于
class A<one ,two, three>:public one,public two,public three
*/
return 0;
}
在多重继承当中,我们都知道,子类对象的this和继承的第一个父类的this是一样的。在执行类模板A的实例化时依次执行one,two,three的构造函数进行初始化工作,最后执行A的构造函数。