473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

list find_if usage

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<GENCHECKNAMES;
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 <liststructure, 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
Jun 27 '08 #1
3 2194
In article <MP************************@news.cox.net>, mr*****@cox.net
says...
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<{{
Jun 27 '08 #2
Hi,
struct GENCHECK
{
char genCode;
string firstName;
} gWork;
typedef list<GENCHECKNAMES;
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
Jun 27 '08 #3
On May 12, 9:33 am, mrc2...@cox.net (Mike Copeland) wrote:
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<GENCHECKNAMES;
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 <liststructure, 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<GENCHECKNAMES;
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;

}
};
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paresh Patel | last post by:
Hi, I have a list of Point pointer like, list<Point *> ptList; now if I want to find the Point that has some unique id, how do i do it?
14
by: mikets | last post by:
Hi there, I found out that very often I use the following construct: for (it = myvec.begin(); it != myvec.end(); ++it) { if (it->name() == "myname") break; } Certainly, the container the...
1
by: John Black | last post by:
Hi, In using find_if() you need to name a comparision function which normally is a static function, but sometimes it is really inconvinient for this, let's take this example, class MyClass{...
4
by: Michael | last post by:
Hi, I'm having a few problems getting the following find_if to work class Entity { }; class factory {
5
by: dave_if | last post by:
I have a vector of TCard objects, I am sorting them based on the the box field. That part works fine (finally!). I would then like to random_shuffle all cards that are in a particular box, that is,...
18
by: ma740988 | last post by:
Trying to get more acclimated with the use of function objects. As part of my test, consider: # include <vector> # include <iostream> # include <algorithm> #include <stdexcept> #include...
3
by: devel | last post by:
Hello, Could someone tell me why the find_if statement applied to my multimap dictionnary is doesn't compile? Does this algorithm doesn't work on a multimap? I don't understand why the...
1
by: AlanJSmith | last post by:
can some clever guru help please. I am porting some C++ 6.0 projects to C++ VS2005 and find_if no longer exists in vector, i am not sure what to do. i am only at begginer level so please dont get...
8
by: Mike Copeland | last post by:
I am trying to learn/use the STL <listto 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 ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.