Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Issues using 2015.2 version
Re: Issues using 2015.2 version [message #45929 is a reply to message #45891] Wed, 27 January 2016 22:42 Go to previous messageGo to previous message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Do you really want to pass full copy?

I think for example for "Save" a const reference is much better, i.e.:
int SaveMasterRecord(const Vector<String> & t);

About the sort... you probably want to keep "pairs" intact?
Then you can again use const reference as input for the function.

But maybe you should check for the built-in Sort, like this:
    Vector<int> pairs{1, 4, 2, 3};
    Vector<int> sortedPairs = clone(pairs);
    Sort(sortedPairs, [](const int & a, const int & b){return a < b;} );
    // lambda expression used for simple "a is less than b" predicate here
    // to give you idea, how you can code your own comparator for "Pair" type
    //(the "less than" is default predicate of Upp::Sort(T & container); )


So if you would define operator < in Pair class, you would be able to write:
    Vector<Pair> sortedPairs = clone(pairs);
    Sort(sortedPairs);


Anyway, passing full copy of Vector to function does make little sense to me, only when you actually store the parameter somewhere... but in most cases you want either just to read the data (const Vector & v), or you want to
manipulate them, but the owner of the Vector is still the caller, so you want to operate on his instance: (Vector & v);
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Empty Template vs CtrlLib application with main window
Next Topic: Problem in example code
Goto Forum:
  


Current Time: Mon May 13 15:47:41 CEST 2024

Total time taken to generate the page: 0.01704 seconds