[Interest] Container members in abstract base class?

Jonathan Greig redteam316 at gmail.com
Thu May 23 20:57:37 CEST 2013


I have implemented the type() method for all of my derived classes so that
qgraphicsitem_cast would work. I just tested it out and apparently it will
not work unless the value returned is an enum of the class. Returning an
enum that isn't part of the class fails every time.
I'm showing this here incase someone else ruins into the same pitfall, as
qgraphicsitem_cast doesn't explain this in the documentation and the only
place to find the way it will work is in the examples:

//ENUMFROMINCLUDEDHEADER is greater than UserType

//will not work as a one liner :(
virtual int type() const { return ENUMFROMINCLUDEDHEADER; }

//will work ONLY if it is named Type
enum { Type = ENUMFROMINCLUDEDHEADER };
virtual int type() const { return Type; }

- Swyped from my droid.

On May 23, 2013 12:29 PM, "Constantin Makshin" <cmakshin at gmail.com> wrote:

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:...

_______________________________________________
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/b274b151/attachment.html>


More information about the Interest mailing list