In C++11 I have a problematic line, when it's commented my programs runs perfect. when I uncomment it it causes tons of errors.
My line is:
jobs.insert(std::lower_bound(jobs.begin(), jobs.end(), job), job);
In the following function:
void JobsList::addJob(Command *cmd, bool isStopped) {
JobEntry tmp{};
tmp.pid = 0;
//getLastJob(&tmp.jid);
++tmp.jid;
tmp.stopped = isStopped;
tmp.cmd = cmd->cmd;
time(&tmp.in_time);
for (auto &job : jobs) {
jobs.insert(std::lower_bound(jobs.begin(), jobs.end(), job), job);
}
}
The error messages I am getting are:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:715:71: error: invalid operands to binary expression ('const JobsList::JobEntry' and 'const JobsList::JobEntry')
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
~~~ ^ ~~~
and:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:4208:13: note: in instantiation of member function 'std::__1::__less<JobsList::JobEntry, JobsList::JobEntry>::operator()' requested here
if (__comp(*__m, __value_))
^
At first I thought it's a problem with include but I already have:
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <sstream>
#include <sys/wait.h>
#include <iomanip>
#include <algorithm>
#include <iterator>
Plus here are more details:
class JobsList {
public:
class JobEntry {
public:
pid_t pid, jid;
string cmd;
time_t in_time;
bool stopped;
};
std::list<JobEntry> jobs;
public:
void addJob(Command* cmd, bool isStopped = false);
}
How to solve this?
Aucun commentaire:
Enregistrer un commentaire