[Kde-pim] KCalCore Ptr typedefs and constness

Sérgio Martins iamsergio at gmail.com
Thu Aug 19 16:29:14 BST 2010


2010/8/19 David Jarvie <djarvie at kde.org>

> I wonder if in addition to such typedefs as KCalCore::Event::Ptr, there
> should also be
>
> typedef QSharedPointer<const KCalCore::Event> ConstPtr;
>
> AFAICS, currently it isn't possible using the Ptr types to have a pointer
> to const data. Specifying
>
> const Ptr
>
> will only make the pointer const, not the data pointed to.
>
> Or is QSharedPointer much cleverer than I imagine?
>

Hello David,


Unfortunately it isn't as simple as adding a typedef.

ConstPtr will give you a false sense of security and can be breached when
you access getters which return non-const pointers:

ConstPtr incidence( someIncidence );
Person *person = incidence->organizer();
person->setName( "foo" ); //ups

We would have to duplicate(overload) every function that returns a pointer
to avoid this.



Regards,
Sérgio Martins
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list