Wrapping allocated output parameters with a scoped_ptr/array
Posted
by Danra
on Stack Overflow
See other posts from Stack Overflow
or by Danra
Published on 2010-04-08T08:38:23Z
Indexed on
2010/04/08
8:43 UTC
Read the original article
Hit count: 333
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
© Stack Overflow or respective owner