list find_if usage

M

Mike Copeland

I am trying to learn and use STL lists, and I'm getting a compile
error with initial declarations. Here;s the code I have so far:
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 compiler error (MS VS6.0) is:

error C2039: 'firstName' : is not a member of 'list<struct
GENCHECK,class std::allocator<struct GENCHECK> >'

on the "bool operator" line in the class definition.

I constructed this code from examples I found in various places, but
nothing I found does quite what I'm trying here. Basically, I'm trying
to build a routing that populates this <list> structure, then searches
for matches (or mismatches) on list via the string element of the
object. What am I doing wrong here?
If there is another STL type I should be using for this application,
or if I should use another "search" technique, please suggest that, as
well. TIA
 
M

Mike Copeland

I am trying to learn and use STL lists, and I'm getting a compile
error with initial declarations. Here;s the code I have so far:
struct GENCHECK // Gender Check data
[deleted...]

Everyone, my apologies: my newsreader (Gravity) reported that my
original message one this topic _failed_ - and afaics it didn't get sent
- but now I see that it did post...along with the reconstructed post I
made a few minutes later. I know about the sin of double-posting (and
impatience!), but my reader led me astray... 8<{{
 
O

Oleg Gaier

Hi,
struct GENCHECK
{
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 list<GENCHECK> (or NAMES) has not the member firstName. Only struct
GENCHECK has it.

Greetings
 
V

Vulcan

I am trying to learn and use STL lists, and I'm getting a compile
error with initial declarations. Here;s the code I have so far:
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 compiler error (MS VS6.0) is:

error C2039: 'firstName' : is not a member of 'list<struct
GENCHECK,class std::allocator<struct GENCHECK> >'

on the "bool operator" line in the class definition.

I constructed this code from examples I found in various places, but
nothing I found does quite what I'm trying here. Basically, I'm trying
to build a routing that populates this <list> structure, then searches
for matches (or mismatches) on list via the string element of the
object. What am I doing wrong here?
If there is another STL type I should be using for this application,
or if I should use another "search" technique, please suggest that, as
well. TIA

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<GENCHECK, bool>
{ // predicate class to perform structure element comparison
string s;
public:
explicit nameEqual (const string &ss) : s(ss) {}
bool operator() (const GENCHECK &e) const { return e.firstName
== s;

}
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top