M
Mike Copeland
I am trying to learn/use the STL <list> to implement a small
application. I didn't get very far before I got a compile error that
befuddles me. Here's the code:
struct GENCHECK // Gender Check data
{
char genCode;
string firstName;
} gWork;
typedef list<GENCHECK> NAMES;
NAMES genData;
list<GENCHECK>::iterator gIter;
class nameEqual : public unary_function<NAMES, bool>
{ // predicate class to perform structure element comparison
string s;
public:
explicit nameEqual (const string &ss) : s(ss) {}
bool operator() (const NAMES &e) const { return e.firstName == s; }
};
The error (VS 6.0) is:
error C2039: 'firstName' : is not a member of
'list<struct GENCHECK,class std::allocator<struct GENCHECK> >'
and I don't understand why it fails to compile. This code was cobbled
from various sources that by themselves worked, but this doesn't...
I'm open to other ways to achieve my goal: which is to populate a
list (or whatever), search it for a match against the string element of
each object, and adding to the list if I don't find a match. The code
above (so far) is only my attempt to declare the data structures and
define a comparison function. Please advise. TIA
application. I didn't get very far before I got a compile error that
befuddles me. Here's the code:
struct GENCHECK // Gender Check data
{
char genCode;
string firstName;
} gWork;
typedef list<GENCHECK> NAMES;
NAMES genData;
list<GENCHECK>::iterator gIter;
class nameEqual : public unary_function<NAMES, bool>
{ // predicate class to perform structure element comparison
string s;
public:
explicit nameEqual (const string &ss) : s(ss) {}
bool operator() (const NAMES &e) const { return e.firstName == s; }
};
The error (VS 6.0) is:
error C2039: 'firstName' : is not a member of
'list<struct GENCHECK,class std::allocator<struct GENCHECK> >'
and I don't understand why it fails to compile. This code was cobbled
from various sources that by themselves worked, but this doesn't...
I'm open to other ways to achieve my goal: which is to populate a
list (or whatever), search it for a match against the string element of
each object, and adding to the list if I don't find a match. The code
above (so far) is only my attempt to declare the data structures and
define a comparison function. Please advise. TIA