https://blog.csdn.net/qq_45662588/article/details/123993484
class Programmer
{
public:
Programmer(string name, int age)
{
this->name = name;
this->age = age;
}
~Programmer()
{
}
void Print()
{
cout << this->name << " " << this->age << endl;
}
private:
string name;
int age;
};
template<typename T>
class Company
{
T* t;
public:
template<typename ...Args>
void Alloc(Args ... args)
{
t = new T(args...);
}
void Print()
{
t->Print();
}
template<typename ...Args>
T* GetProgrammer(Args ...args) //参数args,起个名字
{
return new T(args...); //可变的参数展开
}
};
int main()
{
Programmer* p = new Programmer("xiaoming", 12);
p->Print();
Company<Programmer> c;
c.Alloc("xiaoming", 13);
c.Print();
c.GetProgrammer("aaa", 14);
delete p;
return 0;
}