by evincarofautumn · 14y ago · 0 comments
Image* image = allocate_image(…);
…
deallocate_image(image);
↓
struct ImageDeleter {
void operator()(void* image) const {
deallocate_image(image);
}
};
unique_ptr<Image, ImageDeleter> image(allocate_image(…));
That certainly can’t work everywhere, but I have yet to be failed by it. std::unique_ptr<Image, void (*)(Image *)>(image, deallocate_image);scoped_ptr<Image> image(allocate_image(...));