However, class QSharedDataPointer
has it.
I always have to define a Class::pointer
typedef
for shortance and create a pointer with Class::pointer(new Class)
.
Does anyone know the reasoning for this?
However, class QSharedDataPointer
has it.
I always have to define a Class::pointer
typedef
for shortance and create a pointer with Class::pointer(new Class)
.
Does anyone know the reasoning for this?
I suspect the reason why T* () operator doesn't exist is because there's the T* data() function which, like many of the other Qt classes such as QString, QByteArray etc. all provide a data() function to access the underlying data of a Qt class.
This maintains a standard interface across Qt classes.
Also, by overloading the operator, it's very easy to make a mistake if one were to change the underlying data and not realise it here. Using the data() function makes it a bit more obvious what you're doing, in my opinion.
The data() function for QSharedPointer also warns not to delete the returned pointer, or pass it to anything which could delete it, so I see it as a function which is there if you really need it, but better if you can avoid it and if you do use it, think carefully about what is happening.
As for QSharedDataPointer, according to the documentation, calling the operator here calls detach(), making it safe to call.