Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 在对象列表的remove_if中包含更多参数_List_Visual C++_Remove If - Fatal编程技术网

List 在对象列表的remove_if中包含更多参数

List 在对象列表的remove_if中包含更多参数,list,visual-c++,remove-if,List,Visual C++,Remove If,如果这是一个平凡的问题,我很抱歉,但我很难找到一个明确的答案。我有一个称为事件的用户定义对象列表,它又是事件模拟的一部分。我想从列表中删除具有其成员之一(类型)的特定值的对象,该值由用户动态提供。到目前为止,我得到的相关代码(在删除所有对“a”的引用后,该代码使用常量): //头文件中的事件类 班级活动 { 公众: 双tte; int类型,代码; }; //源文件 bool销毁(常量事件和检查,int a) { 返回检查。类型==a; } int main() { 列出事件列表; //正在将事件

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

//头文件中的事件类
班级活动
{
公众:
双tte;
int类型,代码;
};
//源文件
bool销毁(常量事件和检查,int a)
{
返回检查。类型==a;
}
int main()
{
列出事件列表;
//正在将事件添加到列表中
cin>>a;
事件列表。如果(销毁(a)),则删除事件列表;
我想问题在于,不能使用remove_if函数传递变量“a”;它应该只有一个参数,而不是两个。您对如何处理这个问题有什么建议吗


提前谢谢你!

事件列表。如果([a](const-event&check){返回销毁(check,a);})
谢谢你Igor,如果我理解正确,你添加了一个lambda,它将启动销毁功能,再次感谢你!另请参阅:
std:bind
// 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));