I'm trying to store data from a file into a vector of objects and then sorting the data members but I'm getting the errors "Cannot determine which instance of overloaded function "sort" is intended". I've tried using lambdas with sort and also thought it might be the way I've created my comparison function (is it a.hour > b.hour or should I use a.getHour() and b.getHour()?) I actually want to sort the vector by both hours and minutes but testing it on only hours first doesn't seem to work. This is what I have so far
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <fstream>
using namespace std;
class time {
int hour;
int minute;
public:
time(int h, int m) {
hour = h;
minute = m;
}
int getHour() { return hour; }
int getMinute() { return minute; }
};
class Times {
vector<time> t;
public:
Times(string fileName) {
//
}
void parse(ifstream& file) {
//
sort.(t.begin(), t.end(), lowerThan);
//sort.(t.begin(), t.end(), [] (time& a, time& b) { return a.hour < b.hour; })
}
void display() {
for (size_t i = 0; i < t.size(); i++) {
cout << t[i].getHour() << ":" << t[i].getMinute() << endl;
}
}
static bool lowerThan(time& a, time& b) { return a.getHour() < b.getHour(); }
};
int main() {
Times times("File.txt");
times.display();
system("pause");
return 0;
}