c++ - How to avoid duplicate code -
as shown in pictures, 2 pieces of code same slight differences. each duplicate might create trouble, if encounter such situations, how supposed solve them?
it depends on case.
in general add function knows both ways , return value need in every case.
so in case like
bool myfuction(bool condition, int i, int k) {   if(condition == true)   {     return (i + min_size + k < ck_size);    }   else   {     return (i - min_size - k >= ck_size);   } }   now can call myfunction(..)
the bool condition condition wether decide use first or second way. 
Comments
Post a Comment