Whats wrong with my template function, its giving me the error of no known conversion?

Viewed 51

So here is my template, which has a findMax function in order to find the largest rectangle object in a vector:

template<typename Object, typename Comparator> 
const Object & findMax(const std::vector<Object> & rectangles, 
Comparator cmp) { 
   int MAX = 0; 
 
   for(int i = 1; i < rectangles.size(); i++) { 
      if(cmp(rectangles[MAX], rectangles[i])) { 
         MAX = i; 
      } 
   } 
   return rectangles[MAX]; 
}

and here is the the line of code where the error occurs:

rectangleVec[findMax(rectangleVec,CompareArea::isLessThan)].display();

My display function works, and now I'm simply trying to display the rectangle is finds largest, but I get the error:

candidate function not viable: no known conversion from 'const Rectangle' to 'std::vector::size_type

I'm stumped, what should I try?

0 Answers
Related