Wrapping allocated output parameters with a scoped_ptr/array
- by Danra
So,
I have some code which looks like this:
byte* ar;
foo(ar) // Allocates a new[] byte array for ar
...
delete[] ar;
To make this safer, I used a scoped_array:
byte* arRaw;
scoped_array ar;
foo(arRaw);
ar.reset(arRaw);
...
// No delete[]
The question is, Is there any existing way to do this using just the scoped_array, without using a temporary raw array?
I can probably write an in-place "resetter" class, just wondering if the functionality exists and I'm missing it.
Thanks,
Dan