
15 Oct
2009
15 Oct
'09
9:15 p.m.
vicente.botet wrote:
Hi,
On TBoost.STM, I need to do something before deleting an array on each one of the elements of the array, or more precissely with the address of each one of the elements.
T* ptr = new T[3];
// in another file, the number of elements to which ptr points is unknown. // before deleting for (size_t i=0; i< 'ptr size'; ++i) { // do something with &ptr[i] } delete [] ptr;
As the number of elemenst is unknow in the separated unit, I have no mean to iterate on ptr to get the address of the elements.
You just have to remember the size of the allocation. const ptr_size = 3; T* ptr = new T[ptr_size]; That's all there is to it! Bo Persson