0

如果这是一个平凡的问题,我深表歉意,但我很难找到一个明确的答案。我有一个称为事件的用户定义对象列表,它又是事件模拟的一部分。我想从列表中删除具有其成员之一(类型)的特定值的对象,该成员由用户动态提供。到目前为止我得到的相关代码(在删除所有对“a”的引用之后,它与常量一起使用):

// The Event class from a header file

class Event
{
public:
    double tte;
    int type, code;
};

// Source file

bool destroy(const Event & check, int a)
{
    return check.type == a;
}

int main()
{
list<Event> event_list;
// events are being added to the list
cin >> a;
event_list.remove_if(destroy(a));

我认为问题在于无法使用 remove_if 函数传递变量“a”;它应该只有一个参数,而不是两个。你对如何处理这个问题有什么建议吗?

先感谢您!

4

0 回答 0