M
Mike Copeland
In the following code, I get a C2679 error that I don't know how to
handle. The error says I don't have a "binary = operator", but I don't
know what that means, nor how to correct it.
I guess the cause of the problem lies with the string within the
struct, but I need the comparison operator for the sort, don't I?
Please advise. TIA
#include <string>
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
struct TIMESTRUCT
{
string time_bib;
bool operator <(const TIMESTRUCT &rhs) const
{
return time_bib < rhs.time_bib;
}
} workTime;
typedef list<TIMESTRUCT> TIMEVEC;
TIMEVEC timeVect;
list<TIMESTRUCT>::iterator timeIter;
int main(int argc, char *argv[])
{
string wsT;
workTime.time_bib = "Sam", timeVect.push_back(workTime);
workTime.time_bib = "Libby", timeVect.push_back(workTime);
workTime.time_bib = "Bob", timeVect.push_back(workTime);
workTime.time_bib = "Carol", timeVect.push_back(workTime);
workTime.time_bib = "Ted", timeVect.push_back(workTime);
workTime.time_bib = "Alice", timeVect.push_back(workTime);
sort(timeVect.begin(), timeVect.end());
for(timeIter = timeVect.begin(); timeIter != timeVect.end();
timeIter++)
{
workTime = timeIter->time_bib; <- C2679 error
}
return;
}
handle. The error says I don't have a "binary = operator", but I don't
know what that means, nor how to correct it.
I guess the cause of the problem lies with the string within the
struct, but I need the comparison operator for the sort, don't I?
Please advise. TIA
#include <string>
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
struct TIMESTRUCT
{
string time_bib;
bool operator <(const TIMESTRUCT &rhs) const
{
return time_bib < rhs.time_bib;
}
} workTime;
typedef list<TIMESTRUCT> TIMEVEC;
TIMEVEC timeVect;
list<TIMESTRUCT>::iterator timeIter;
int main(int argc, char *argv[])
{
string wsT;
workTime.time_bib = "Sam", timeVect.push_back(workTime);
workTime.time_bib = "Libby", timeVect.push_back(workTime);
workTime.time_bib = "Bob", timeVect.push_back(workTime);
workTime.time_bib = "Carol", timeVect.push_back(workTime);
workTime.time_bib = "Ted", timeVect.push_back(workTime);
workTime.time_bib = "Alice", timeVect.push_back(workTime);
sort(timeVect.begin(), timeVect.end());
for(timeIter = timeVect.begin(); timeIter != timeVect.end();
timeIter++)
{
workTime = timeIter->time_bib; <- C2679 error
}
return;
}