Thursday 15 August 2013

c++11 - Summing up values by calling a method of objects in a vector in c++ -


Is this a good way to write code in C ++ 11?

  int RawSheet :: getNumberOfCities () const {int n = 0; For (Cost Auto and C: Countries) {n + = c.getNumberOfCities (); } Return n; }   

Thanks

Experiment with lambda callback: < / P>

  #include & lt; Algorithm & gt; Int RawSheet :: getNumberOfCities () const {return std :: accumulate (countries.begin (), countries.end (), 0, [] (Rochetta Constant and OA1, Rachit Concent and Op 2) {return op1.getNumberOfCities ( ) + Op2.getNumberOfCities ();}); }    

No comments:

Post a Comment