QScopedArrayPointer Class
template <typename T, typename Cleanup> class QScopedArrayPointerThe QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects, and deletes it upon destruction. More...
| Header: | #include <QScopedArrayPointer> |
| Inherits: | QScopedPointer |
Public Functions
| QScopedArrayPointer() | |
| QScopedArrayPointer(D *p) | |
| void | swap(QScopedArrayPointer<T, Cleanup> &other) |
| T & | operator[](int i) |
| const T & | operator[](int i) const |
Detailed Description
\inmoduleQtCore
\since4.6 \reentrant \ingroup misc
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[] }
Member Function Documentation
QScopedArrayPointer::QScopedArrayPointer()
Constructs a QScopedArrayPointer instance.
[explicit] template <typename D, int> QScopedArrayPointer::QScopedArrayPointer(D *p)
Constructs a QScopedArrayPointer and stores the array of objects pointed to by p.
[noexcept] void QScopedArrayPointer::swap(QScopedArrayPointer<T, Cleanup> &other)
\deprecated[6.1] Use std::unique_ptr instead; this function may let a pointer escape its scope.
Swap this pointer with other.
T &QScopedArrayPointer::operator[](int i)
Provides access to entry i of the scoped pointer's array of objects.
If the contained pointer is nullptr, behavior is undefined.
Note: In Qt versions prior to 6.5, i was of type int, not qsizetype, possibly causing truncation on 64-bit platforms.
See also isNull().
const T &QScopedArrayPointer::operator[](int i) const
Provides access to entry i of the scoped pointer's array of objects.
If the contained pointer is nullptr behavior is undefined.
Note: In Qt versions prior to 6.5, i was of type int, not qsizetype, possibly causing truncation on 64-bit platforms.
See also isNull().