// 变长模板
#include "iostream"
using namespace std;
class Test
{
public:
Test(){}
~Test()
{
cout << " destory " << endl;
}
};
void DELETE()
{
cout << "结束了" << endl;
}
template<typename T, typename...Types>
void DELETE(T& first, Types&...agrs)
{
if (first)
{
delete first;
first = nullptr;
}
DELETE(agrs...);
}
int main()
{
Test* t1 = new Test;
Test* t2 = new Test;
Test* t3 = new Test;
Test* t4 = new Test;
DELETE(t1, t2, t3, t4);
getchar();
return 0;
}
重学C++ 变长模板
最新推荐文章于 2024-08-15 00:15:00 发布