[KDev4] let's clearify VCS interfaces

Matt Rogers mattr at kde.org
Mon Apr 2 16:23:18 UTC 2007


On Monday 02 April 2007 10:18, Andreas Pakulat wrote:
> On 02.04.07 08:40:47, Kris Wong wrote:
> > >> QMap& KSomeClass::getMap()
> > >> {
> > >>       QMap map;
> > >>       map.insert(xxxx);
> > >>       return map;
> > >> }
> > >> This is what I meant. The returned reference is invalid because it
> > >> is destroyed after the function returns.
> > >>
> > >> Below is correct.
> > >> void KSomeClass::getMap( QMap &map )
> > >> {
> > >>     map.insert(xxx);
> > >> }
> > >
> > > Well, we can make it QMap& KSomeClass::getMap() with this:
> > >
> > > return QMap(map);
> > >
> > > Because then the returned reference won't be destroyed but still
> >
> > contain
> >
> > > a copy of the map. You know I don't like parameters like QMap& too
> >
> > much,
> >
> > > unless they're really needed. It can easily be confused with const
> >
> > QMap&
> >
> > > and people will wonder what the parameter is supposed to do...
> >
> > Why return a reference here?
>
> Because users then don't have to store the map if they want to iterate
> over it.
>

They should keep a copy of the map anyways. Qt classes are implicitly shared, 
so I doubt this has much impact on memory usage.
-- 
Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20070402/da57ff81/attachment.sig>


More information about the KDevelop-devel mailing list