[Interest] Container members in abstract base class?

Andre Somers andre at familiesomers.nl
Wed May 22 22:12:56 CEST 2013

Op 22-5-2013 21:34, Thiago Macieira schreef:
> On quarta-feira, 22 de maio de 2013 16.52.29, Jonathan Greig 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-dyna
>> mic-cast
> A C cast is equivalent to a chain of reinterpret_cast and const_cast. It does
> not do static casting or dynamic casting, which means it will not do pointer
> adjustments properly.
> So, as a rule of thumb: do not use C-style casts in C++ code and always use
> the least invasive C++ cast operator that you can use. And another rule of
> thumb: dynamic_casts are always checked[*], all the other casts are never
> checked.
You're overlooking our very own qobject_cast. That one works on QObject 
derived classes without requiring the use of RTTI in the compiler, and 
work across library boundaries. So, if your class inherits QObject, I'd 
prefer qobject_cast instead.


More information about the Interest mailing list