[Interest] Container members in abstract base class?

Constantin Makshin cmakshin at gmail.com
Thu May 23 19:29:27 CEST 2013


Yes, qgraphicsitem_cast isn't as powerful as dynamic_cast, but this
simplicity also makes it faster.

Anyway, Jonathan asked about casting C++ objects and now has several
methods to choose from. :-)
On May 23, 2013 9:17 PM, "Jan Kundrát" <jkt at flaska.net> wrote:

> On Thursday, 23 May 2013 19:04:53 CEST, Constantin Makshin wrote:
> > There's also qgraphicsitem_cast made specifically for casting to classes
> > derived from QGraphicsItem.
>
> It is also of very limited value in real world because it does not support
> inheritance -- it can only cast to the exact type of the item in question.
>
> Suppose you have a hierarchy -- C derives from B which derives from A. A
> dynamic_cast of a C to all of B and A will succeed, but a
> qgraphicsitem_cast will return a null pointer when casting a C* into either
> B* or C*, only succeeding when casting to A*. Depending on what you're
> looking for, being able to fully utilize the inheritance tree might or
> might not be important for you.
>
> (Actually, the bits above are a little bit simplified; the casting is
> performed based on the target class' Type member, so in cases where you
> e.g. derive from a QGraphicsItemText but forget to provide your own Type
> value, a cast to QGraphicsItemText will succeed. Of course, you cannot
> distinguish between a QGraphicsItemText and your own class via
> qgraphicsitem_cast in this situation.)
>
> Cheers,
> Jan
>
> --
> Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130523/045405d5/attachment.html>


More information about the Interest mailing list