I am a newbie. I tried this template function in visual studio, but I'm getting the following syntax error:
Missing type specifier - int assumed. Note: C++ does not support default-int
template <typename Object,typename Comparator>
const Object & findMax(const vector<Object> &a, Comparator comp)
{
int maxIndex = 0;
for(int i = 1; i < a.size(); i++){
if(comp.isLessThan(a[maxIndex], a[i]))
maxIndex = i;
}
return a[maxIndex];
}
class LessThanByWidth {
public:
bool isLessThan(const Rectangle &a, const Rectangle &b) const{
return (a.getWidth() < b.getWidth());
}
};
I don't know what exactly the problem is. This function is not declared inside any class.