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

Issue

This Content is from Stack Overflow. Question asked by Matthew Joel

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 im 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

Im stumped, what should i try?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?