with your code as it stands, the answer to both questions is:
you can't!
all is not lost though
first you need to provide accessors for your data
Code:
class MyClass
{
public:
void SetNum(int);
void SetChar(char);
int GetNum() const { return num; }
charGetChar() const { return ch; }
private:
int num;
char ch;
};
now that we can access the data we can build a predicate. a predicate a basically a function returning a bool that satisfies a condition.
so for your first request, remove where num ==5
Code:
class NumEquals
{
int num;
public:
NumEquals(int aNum)
: num(aNum)
{}
// operator() is what's called when you do NumEquals()
bool operator()(const MyClass& obj)
{
return obj.GetNum() == 5;
}
};
int main()
{
std::list<MyClass> ClassList;
//populate list
ClassList.remove_if(NumEquals(5));
return 0;
}
for your second request just write a new predicate and change op() to include both conditions.
but that's a pain in the ass, writing all these predicates, isn't it?
that's why you want to use boost.bind
so you can do this:
Code:
#include <boost/bind.hpp>
using namespace boost;
int main()
{
std::list<MyClass> ClassList;
//populate list
// this basically calls GetNum for each object in ClassList and compares it to 5
// _1 is a placeholder for the objects in the list
ClassList.remove_if(bind(MyClass::GetNum, _1) == 5);
return 0;
}
if you don't think that's cool then ice-cream, you're shouldn't do C++!