diff options
author | Martin Smith <msmith@trolltech.com> | 2010-02-23 12:43:50 (GMT) |
---|---|---|
committer | Martin Smith <msmith@trolltech.com> | 2010-02-23 12:43:50 (GMT) |
commit | 28e3d3516ebe88f7353fde44194aba5b7d1d8710 (patch) | |
tree | 0a0470a624e585cbfdb9763e145b0b2dacd62daa | |
parent | 9629681e7b3d69456bd6c5905c267b3d08b6243f (diff) | |
download | Qt-28e3d3516ebe88f7353fde44194aba5b7d1d8710.zip Qt-28e3d3516ebe88f7353fde44194aba5b7d1d8710.tar.gz Qt-28e3d3516ebe88f7353fde44194aba5b7d1d8710.tar.bz2 |
doc: Added QScopedArrayPointer and corrected QScopedPointer snippet.
Task: QTBUG-7766
-rw-r--r-- | doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qscopedpointer.cpp | 55 |
2 files changed, 56 insertions, 1 deletions
diff --git a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp index c068ba9..4158388 100644 --- a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp +++ b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp @@ -128,7 +128,7 @@ private: QScopedPointer<int, QScopedPointerArrayDeleter<int> > arrayPointer(new int[42]); // this QScopedPointer frees its data using free(): -QScopedPointer<int, QScopedPointerPodDeleter<int> > podPointer(reinterpret_cast<int *>(malloc(42))); +QScopedPointer<int, QScopedPointerPodDeleter> podPointer(reinterpret_cast<int *>(malloc(42))); // this struct calls "myCustomDeallocator" to delete the pointer struct ScopedPointerCustomDeleter diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index 12badf0..e7dd769 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -225,4 +225,59 @@ QT_BEGIN_NAMESPACE Swap this pointer with \a other. */ +/*! + \class QScopedArrayPointer + + \brief The QScopedArrayPointer class stores a pointer to a + dynamically allocated array of objects, and deletes it upon + destruction. + + \since 4.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: + + \code + void foo() + { + QScopedArrayPointer<int> i(new int[10]); + i[2] = 42; + ... + return; // our integer array is now deleted using delete[] + } + \endcode +*/ + +/*! + \fn QScopedArrayPointer::QScopedArrayPointer(T *p = 0) + + Constructs this QScopedArrayPointer instance and sets its pointer + to \a p. +*/ + +/*! + \fn T *QScopedArrayPointer::operator[](int i) + + Provides access to entry \a i of the scoped pointer's array of + objects. + + If the contained pointer is \c null, behavior is undefined. + + \sa isNull() +*/ + +/*! + \fn T *QScopedArrayPointer::operator[](int i) const + + Provides access to entry \a i of the scoped pointer's array of + objects. + + If the contained pointer is \c null, behavior is undefined. + + \sa isNull() +*/ + QT_END_NAMESPACE |