473,396 Members | 2,018 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.

Why won't this list remove_if code compile

Hi

I have a class CRequest with a function:
bool IsFinished() const;

I have a list of these CRequests - list<CRequestmylist.

I create a function object to find if a CRequest is finished:
class is_finished : public std::unary_function<CRequest, bool>
{
public:
bool operator() (CRequest req) { return req.IsFinished(); }
};

And I use remove_if like this:
m_RequestList.remove_if(is_finished());

But I get a compile error:
error C2664: 'remove_if' : cannot convert parameter 1 from 'class
is_finished' to 'class std::binder2nd<struct std::not_equal_to<class
CRequest'
No constructor could take the source type, or constructor overload
resolution was ambiguous

How can I fix this?
Jun 27 '08 #1
3 2566
On 2008-05-24 11:05:20 -0400, "Angus" <no****@gmail.comsaid:
>
I have a class CRequest with a function:
bool IsFinished() const;

I have a list of these CRequests - list<CRequestmylist.

I create a function object to find if a CRequest is finished:
class is_finished : public std::unary_function<CRequest, bool>
{
public:
bool operator() (CRequest req) { return req.IsFinished(); }
};

And I use remove_if like this:
m_RequestList.remove_if(is_finished());

But I get a compile error:
error C2664: 'remove_if' : cannot convert parameter 1 from 'class
is_finished' to 'class std::binder2nd<struct std::not_equal_to<class
CRequest'
No constructor could take the source type, or constructor overload
resolution was ambiguous

How can I fix this?
Get a newer compiler.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jun 27 '08 #2
Hi!

Angus schrieb:
public:
bool operator() (CRequest req) { return req.IsFinished(); }
I guess the operator should be a const function.

Frank
Jun 27 '08 #3
"Angus" <no****@gmail.comwrote:
I have a class CRequest with a function:
bool IsFinished() const;

I have a list of these CRequests - list<CRequestmylist.

I create a function object to find if a CRequest is finished:
class is_finished : public std::unary_function<CRequest, bool>
{
public:
bool operator() (CRequest req) { return req.IsFinished(); }
};

And I use remove_if like this:
m_RequestList.remove_if(is_finished());

But I get a compile error:
error C2664: 'remove_if' : cannot convert parameter 1 from 'class
is_finished' to 'class std::binder2nd<struct std::not_equal_to<class
CRequest'
No constructor could take the source type, or constructor overload
resolution was ambiguous

How can I fix this?
Try this:

class CRequest
{
public:
bool isFinished() const;
};

void fn( list<CRequestlst )
{
lst.remove_if( mem_fun_ref( &CRequest::isFinished ) );
}
Jun 27 '08 #4

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

Similar topics

2
by: marco_segurini | last post by:
Hi, if I compile the following code I get the error: RemoveIf.cpp(19) : error C2914: 'remove_if' : cannot deduce template argument as function argument is ambiguous #include <algorithm>...
8
by: cpptutor2000 | last post by:
I am using an STL list to store data packets in a network simulator. The data packets are really C structs, which have other C structs inside them. These structs contain unsigned char arrays of...
5
by: Allerdyce.John | last post by:
In STL list, is it safe to do this: list<A> aList; //private attribute of MyClass void MyClass:: aMethod() { list<A>::Iterator iter; for ( iter = aList.begin() ; iter != aList.end() ;...
1
by: Birthe Gebhardt | last post by:
Dear all, I could not find the way to handle 'not normal' list objects, for example using remove_if, find etc. Example : class Todo { public : .. int getNumber(){ return num_;}
16
by: Frank Neuhaus | last post by:
Hi I have some std list, I'd like to traverse. During the traversal, I want to conditionally delete some objects. My code for that is like this right now: for (std::list<myStruct>::iterator...
3
by: Jon Rea | last post by:
Hello all, Sorry if this is long, but I wanted to be specific... Can anyone shed any light on the following errors in the context of the following example code: cullMethod1(); // compiles,...
5
by: Christopher | last post by:
The situation is that a std::list<std::set<std::string is being iterated through. Upon certain criteria some sets become empty. I need to remove the empty sets from the list. Is it safe to...
3
by: subramanian100in | last post by:
There are some operations like sort, remove, remove_if which are available as list<Tmember functions; but vector<T>, deque<Tdo not seem have those functions. If am correct in this, what is the...
12
by: Philip Mueller | last post by:
Hi, I am using multiple stl::list s of different types. Now I want to write a function list<type>::iterator s_erase(list<typel, list<type>::iterator it) that takes an iterator and deletes...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.