Can you use a shared_ptr for RAII of C-style arrays?
I'm working on a section of code that has many possible failure points which cause it to exit the function early. The libraries I'm interacting with require that C-style arrays be passed to the functions. So, instead of calling delete on the arrays at every exit point, I'm doing this: void SomeFunction(int arrayLength) { shared_ptr<char> raiiArray(new char[arrayLength]); pArray = raiiArray.get(); if(SomeFunctionThatRequiresCArray(pArray) == FAILED) { return; } //etc. } I wanted to use unique_ptr , but my current compiler doesn't support it and the reference count overhead doesn't really matter