These macros (MIN and MAX) should be replace with std::min and std::max (see http://www.cplusplus.com/reference/algorithm/min/ in the algorithm header).