[Development] unique_ptr and Qt, Take 2

Thiago Macieira thiago.macieira at intel.com
Sat May 4 01:33:32 CEST 2019

On Friday, 3 May 2019 16:14:09 PDT Иван Комиссаров wrote:
> What I am talking about is that explicit is better than implicit. Taking an
> address of an object on a stack and passing it to a function that (possibly
> can) delete your object is not explicit. Wrapping that operation in a
> construction of a smart pointer is explicit. Moving a unique_ptr is
> explicit. When you’re «casting» your on-a-stack-QFile to a some smart
> pointer, you’re telling the compiler (and other people who read the code)
> «trust me, I know what I’m doing, this is intended».

That I can agree with, but this goes back to the suggestion of our own smart 
QObject pointer classes. In non-compatibility mode, a function that adopts the 
passed object should only accept from another smart pointer. If you pass a 
naked pointer, it should reject and force you to clearly state that you know 
what you're doing.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products

More information about the Development mailing list