[Qt-interest] remove all elements from a QPainterPath

Thiago Macieira thiago at kde.org
Thu Mar 31 16:55:47 CEST 2011


Em quinta-feira, 31 de março de 2011, às 09:34:00, Sean Hayes escreveu:
> Markus,
> 
> Very clever thought. However, I believe that making assignments to the this
> pointer violates the C++ standards and will not compile on most modern
> compilers. Therefore, the following statement should not work.

Making assignments to the this pointer are not permitted. In a member function 
function called:

	MyClass::myMemberFunction()

The this pointer has type:
	MyClass * const

Which means you cannot modify the this pointer. Also note that the function 
CV-qualifiers apply to the class:

	MyClass::myMemberFunction() const -> const MyClass * const
	MyClass::myMemberFunction() volatile -> volatile MyClass * const

That said, note that assignments to the pointee *are* permitted. So the 
following code:

> *this = QPainterPath();

Is perfectly possible. It's simply equivalent to calling:

	this->operator =(QPainterPath());

It's even used in lots of places in Qt and in WebKit:

corelib/io/qfileinfo.cpp:    *this = QFileInfo(file);
corelib/io/qfilesystementry_p.h:        *this = QFileSystemEntry();
corelib/io/qfilesystemwatcher.cpp:            *this = FileInfo(fileInfo);
corelib/io/qurl.h:        *this = resolved(QUrl(QLatin1String("..")));
corelib/plugin/quuid.cpp:        *this = QUuid();
corelib/tools/qbitarray.h:{ *this = QBitArray((asize < 0 ? this->size() : 
asize), aval); return true; }
corelib/tools/qbytearray.cpp:        *this = ba;
corelib/tools/qhash.h:        inline iterator &operator+=(int j) { return 
*this = *this + j; }
corelib/tools/qlinkedlist.h:    *this = QLinkedList<T>();
corelib/tools/qlist.h:    *this = QList<T>();
corelib/tools/qlist.h:            *this = l;

and many more. Use "git grep -F '*this =' src" in the Qt source code to find 
them.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110331/4b5d8c94/attachment.bin 


More information about the Qt-interest-old mailing list