|
#include <vector>
#include <algorithm>
#include "FreePtr.h"
using namespace std;
using namespace FreePtr;
class C
{
char* data_;
public:
C()
{
data_ = new char[512];
}
~C()
{
delete[] data_;
}
};
int main ()
{
vector <C*> objects;
for (int i = 0; i < 20; ++i)
objects.push_back(new C());
for_each(objects.begin(), objects.end(), free_ptr<C>());
objects.clear();
for (int i = 0; i < 20; ++i)
objects.push_back(new C[10]);
for_each(objects.begin(), objects.end(), free_ptr<C, DeleteArray, ZeroPtr>());
objects.clear();
for (int i = 0; i < 20; ++i)
objects.push_back((C*)malloc(sizeof(C)));
for_each(objects.begin(), objects.end(), free_ptr<C, Free>());
objects.clear();
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Born in Kragujevac, Serbia. Now lives in Boston area with his wife and daughters.
Wrote his first program at the age of 13 on a Sinclair Spectrum, became a professional software developer after he graduated.
Very passionate about programming and software development in general.