QScopedArrayPointer 類

template <typename T, typename Cleanup> class QScopedArrayPointer

QScopedArrayPointer 類存儲動態分配對象數組的指針,並在銷毀時刪除它。 更多...

頭: #include <QScopedArrayPointer>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
繼承: QScopedPointer

注意: 此類的所有函數 可重入 .

公共函數

QScopedArrayPointer ()
QScopedArrayPointer (D * p )
T & operator[] (qsizetype i )
const T & operator[] (qsizetype i ) const

詳細描述

A QScopedArrayPointer is a QScopedPointer that defaults to deleting the object it is pointing to with the delete[] operator. It also features operator[] for convenience, so we can write:

void foo()
{
    QScopedArrayPointer<int> i(new int[10]);
    i[2] = 42;
    ...
    return; // our integer array is now deleted using delete[]
}
					

成員函數文檔編製

QScopedArrayPointer:: QScopedArrayPointer ()

Constructs a QScopedArrayPointer instance.

[explicit] template <typename D, if_same_type<D>> QScopedArrayPointer:: QScopedArrayPointer ( D * p )

Constructs a QScopedArrayPointer and stores the array of objects pointed to by p .

T &QScopedArrayPointer:: operator[] ( qsizetype i )

Provides access to entry i of the scoped pointer's array of objects.

If the contained pointer is nullptr , behavior is undefined.

注意: In Qt versions prior to 6.5, i was of type int , not qsizetype , possibly causing truncation on 64-bit platforms.

另請參閱 isNull ().

const T &QScopedArrayPointer:: operator[] ( qsizetype i ) const

Provides access to entry i of the scoped pointer's array of objects.

If the contained pointer is nullptr behavior is undefined.

注意: In Qt versions prior to 6.5, i was of type int , not qsizetype , possibly causing truncation on 64-bit platforms.

另請參閱 isNull ().