我正在尝试做这样的事情:
struct holder {
std::function<void()> destroyer;
template<typename T>
holder(T) = delete;
template<typename T>
holder(std::enable_if< WAS CREATED WITH new > pointer) {
destroyer = [=] { delete pointer; };
};
template<typename T>
holder(std::enable_if< WAS CREATED WITH new[] > array) {
destroyer = [=] { delete[] array; };
};
virtual ~holder() {
destroyer();
};
};
在某种程度上,我可以简单地在一个返回的函数上创建return new test;
和。但我发现它永远不会被视为一个数组,因为它返回一个指针。return = new test[10];
holder
operator new[]
有什么方法可以达到预期的效果吗?
谢谢!:)