On Fri, 20 Oct 2000, Angus Leeming wrote:
> On Fri, 20 Oct 2000, Baruch Even wrote:
> > [on the topic of returning large objects from a function]
> >
> > If it's a large object that has long c-tor time the best method is to
> > return a const refernce as in: Menu const & expand(Buffer *) const;
> >
> > This will make sure that a copy will only occur when it's really
> > necessary, and the object can still be used again as in:
> > menu.expand( ).shrink( )
> >
> > That's the general idea, I've no idea how Menu::expand works currently.
>
> But you can't do this if the Menu object is created within the function,
> because you'll then be referencing something that has gone out of scope.
Indeed, if the object is local to the function this is not a solution and
the only option is to return a const copy of the object.
--
Baruch Even
http://techst02.technion.ac.il/~sbaruch/ (My Site)
http://www.redrival.com/jindor/ (My brothers AD&D site)
" Learn to laugh ... it's the path to true love! "
- The Angel in the movie Michael