[Interest] Container members in abstract base class?

Jonathan Greig redteam316 at gmail.com
Wed May 22 18:52:29 CEST 2013


Thank you André. The dynamic_cast worked perfectly. I'm from a C background
and have been doing C-style casts for years without any major problems.
Apparently this guy has also:)
http://stackoverflow.com/questions/28002/regular-cast-vs-static-cast-vs-dynamic-cast

- Swyped from my droid.

On May 22, 2013 9:21 AM, "André Somers" <andre at familiesomers.nl> wrote:

Op 22-5-2013 16:03, Jonathan Greig schreef:

>          BaseObject* base = (BaseObject*)item;
>          if(base) { base->setObjectRubberPoint(**key, point); }
>
The above looks suspicious. The cast you're doing here is unsafe. Your
check on base on the second line is useless, as the C-style cast you're
using doesn't do any checking. So, my suspicion is that your item isn't a
BaseObject, and thus the method call you make into it is going to fail. Use
a dynamic_cast<BaseObject*>(**item) for your cast instead. That cast _
will_  result in a 0 pointer if the cast fails.



André

-- 
You like Qt?
I am looking for collegues to join me at i-Optics!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130522/b1e4e72d/attachment.html>


More information about the Interest mailing list