[KDev4] let's clearify VCS interfaces
Andreas Pakulat
apaku at gmx.de
Mon Apr 2 15:18:55 UTC 2007
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.
Andreas
--
Chess tonight.
More information about the KDevelop-devel
mailing list