On 20 Oct 2000, Jean-Marc Lasgouttes wrote:

> 
> The method Menu::expand in Menubackend.C has the following signature:
> 
>         /// Expands some special entries of the menu
>         /** The entries with the following kind are exanded to a
>             sequence of Command MenuItems: Lastfiles, Documents,
>             ViewFormats, ExportFormats, UpdateFormats
>         */
>         void expand(Menu & tomenu, Buffer *) const;
>  
> It would have been more reasonable to have something like
>         Menu const expand(Buffer *) const;
> 
> The reason I did not do it is that I was not sure what would happen:
> if you create a temporary object in a function, and return it at the
> end, is the object copied or do you return it without copy? This can
> have some importance if the object is a big vector (think 'table of
> contents'). 
> 
> So what is the right way to return this kind of big objects?

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.

-- 
  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


Reply via email to