重学C++ 变长模板

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/artisans/article/details/81260280
// 变长模板
#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;
}

猜你喜欢

转载自blog.csdn.net/artisans/article/details/81260280