I need a class like std :: auto_ptr for the unsigned char * array allocated by the new []. But auto_ptr only calls delete, not delete [], so I cannot use it.
I also need a function that creates and returns an array. I came out with my own implementation in the ArrayDeleter class, which I use, as in this example:
#include <Utils/ArrayDeleter.hxx>
typedef Utils::ArrayDeleter<unsigned char> Bytes;
void f()
{
unsigned char* xBytes = new unsigned char[10];
return std::auto_ptr<Bytes>(new Bytes(xBytes));
}
...
{
auto_ptr<Bytes> xBytes(f());
}
Is there a more elegant way to solve this problem? (Even using another "popular" library)
source
share