QScopedPointer用于在离开栈作用域时自动销毁堆内存。即将一个非组合类型(数组等)的堆指针交给QScopedPointer析构时delete。
#include <qscopedpointer.h>
class TestScopedPointer
{
public:
~TestScopedPointer()
{
qDebug() << __FUNCTION__;
}
};
QScopedPointer<TestScopedPointer> tsp(new TestScopedPointer);
QScopedPointer<TestScopedPointer> tsp(new TestScopedPointer[2]);//这种无法正确析构,因为其内部实现只是单纯delete