[Interest] Container members in abstract base class?

Alex Malyushytskyy alexmalvtk at gmail.com
Wed May 22 20:15:25 CEST 2013


They are not.
static_cast exists for purpose.


On Wed, May 22, 2013 at 10:10 AM, Constantin Makshin <cmakshin at gmail.com>wrote:

> Well, C-style casts are still useful because, unlike dynamic_cast, they
> need neither RTTI nor run-time checks, making the compiled code somewhat
> smaller and faster. You just need to be very careful with them. :-)
> On May 22, 2013 8:52 PM, "Jonathan Greig" <redteam316 at gmail.com> wrote:
>
>> 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!
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
> _______________________________________________
> 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/20130522/f283d453/attachment.html>


More information about the Interest mailing list