Форум программистов, компьютерный форум CyberForum.ru

STL и функция remove_if - C++

Восстановить пароль Регистрация
 
Рейтинг: Рейтинг темы: голосов - 12, средняя оценка - 5.00
dima11221122
0 / 0 / 0
Регистрация: 30.07.2010
Сообщений: 9
29.09.2010, 00:09     STL и функция remove_if #1
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "stdafx.h"
#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>
.....
struct computer1
{
    int comp_number;
    int comp_mark;
};
 
struct connection1
{
    int side1;
    int side2;
    int conn_mark;
};
 
bool cond_comp(list<computer1>::iterator x)
{
    return (x->comp_mark==1);
}
 
bool cond_conn(list<connection1>::iterator y)
{
    return (y->conn_mark==1);
}
void delete1()
{
    list<computer1>::iterator x;
    x=remove_if(computers.begin(), computers.end(), cond_comp);
    computers.erase(x, computers.end());
 
    list<connection1>::iterator y;
    y=remove_if(connections.begin(), connections.end(), cond_conn);
    connections.erase(y, connections.end());
}
при компиляции указывает на ошибки в библиотеках. текст

c:\program files\microsoft visual studio 9.0\vc\include\algorithm(87) : error C2664: 'bool (std::list<_Ty>::_Iterator<_Secure_validation>)' : cannot convert parameter 1 from 'computer1' to 'std::list<_Ty>::_Iterator<_Secure_validation>'
1> with
1> [
1> _Ty=computer1,
1> _Secure_validation=true
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(96) : see reference to function template instantiation '_InIt std::_Find_if<std::list<_Ty>::_Iterator<_Secure_validation>,bool(__cdecl *)(std::list<_Ty>::_Iterator<true>)>(_InIt,_InIt,_Pr)' being compiled
1> with
1> [
1> _InIt=std::list<computer1>::_Iterator<false>,
1> _Ty=computer1,
1> _Secure_validation=false,
1> _Pr=bool (__cdecl *)(std::list<computer1>::_Iterator<true>)
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(1305) : see reference to function template instantiation '_InIt std::find_if<_FwdIt,bool(__cdecl *)(std::list<_Ty>::_Iterator<_Secure_validation>)>(_InIt,_InIt,_Pr)' being compiled
1> with
1> [
1> _InIt=std::list<computer1>::_Iterator<true>,
1> _FwdIt=std::list<computer1>::_Iterator<true>,
1> _Ty=computer1,
1> _Secure_validation=true,
1> _Pr=bool (__cdecl *)(std::list<computer1>::_Iterator<true>)
1> ]
1> c:\users\дмитрий\desktop\с\stl_computer_net\stl_computer_net\stl_computer_net.cpp(105) : see reference to function template instantiation '_FwdIt std::remove_if<std::list<_Ty>::_Iterator<_Secure_validation>,bool(__cdecl *)(std::list<_Ty>::_Iterator<_Secure_validation>)>(_FwdIt,_FwdIt,_Pr)' being compiled
1> with
1> [
1> _FwdIt=std::list<computer1>::_Iterator<true>,
1> _Ty=computer1,
1> _Secure_validation=true,
1> _Pr=bool (__cdecl *)(std::list<computer1>::_Iterator<true>)
1> ]
1>c:\program files\microsoft visual studio 9.0\vc\include\algorithm(1241) : error C2664: 'bool (std::list<_Ty>::_Iterator<_Secure_validation>)' : cannot convert parameter 1 from 'computer1' to 'std::list<_Ty>::_Iterator<_Secure_validation>'
1> with
1> [
1> _Ty=computer1,
1> _Secure_validation=true
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(4951) : see reference to function template instantiation '_OutIt std::_Remove_copy_if<std::list<_Ty>::_Iterator<_Secure_validation>,_OutIt,bool(__cdecl *)(std::list<_Ty>::_Iterator<true>)>(_InIt,_InIt,_OutIt,_Pr,std::_Range_checked_iterator_tag)' being compiled
1> with
1> [
1> _OutIt=std::list<computer1>::_Iterator<true>,
1> _Ty=computer1,
1> _Secure_validation=false,
1> _InIt=std::list<computer1>::_Iterator<false>,
1> _Pr=bool (__cdecl *)(std::list<computer1>::_Iterator<true>)
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(1311) : see reference to function template instantiation '_OutIt stdext::unchecked_remove_copy_if<std::list<_Ty>::_Iterator<_Secure_validation>,_FwdIt,bool(__cdecl *)(std::list<_Ty>::_Iterator<_Secure_validation>)>(_InIt,_InIt,_OutIt,_Pr)' being compiled
1> with
1> [
1> _OutIt=std::list<computer1>::_Iterator<true>,
1> _Ty=computer1,
1> _Secure_validation=true,
1> _FwdIt=std::list<computer1>::_Iterator<true>,
1> _InIt=std::list<computer1>::_Iterator<true>,
1> _Pr=bool (__cdecl *)(std::list<computer1>::_Iterator<true>)
1> ]
1>c:\program files\microsoft visual studio 9.0\vc\include\algorithm(87) : error C2664: 'bool (std::list<_Ty>::_Iterator<_Secure_validation>)' : cannot convert parameter 1 from 'connection1' to 'std::list<_Ty>::_Iterator<_Secure_validation>'
1> with
1> [
1> _Ty=connection1,
1> _Secure_validation=true
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(96) : see reference to function template instantiation '_InIt std::_Find_if<std::list<_Ty>::_Iterator<_Secure_validation>,bool(__cdecl *)(std::list<_Ty>::_Iterator<true>)>(_InIt,_InIt,_Pr)' being compiled
1> with
1> [
1> _InIt=std::list<connection1>::_Iterator<false>,
1> _Ty=connection1,
1> _Secure_validation=false,
1> _Pr=bool (__cdecl *)(std::list<connection1>::_Iterator<true>)
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(1305) : see reference to function template instantiation '_InIt std::find_if<_FwdIt,bool(__cdecl *)(std::list<_Ty>::_Iterator<_Secure_validation>)>(_InIt,_InIt,_Pr)' being compiled
1> with
1> [
1> _InIt=std::list<connection1>::_Iterator<true>,
1> _FwdIt=std::list<connection1>::_Iterator<true>,
1> _Ty=connection1,
1> _Secure_validation=true,
1> _Pr=bool (__cdecl *)(std::list<connection1>::_Iterator<true>)
1> ]
1> c:\users\дмитрий\desktop\с\stl_computer_net\stl_computer_net\stl_computer_net.cpp(109) : see reference to function template instantiation '_FwdIt std::remove_if<std::list<_Ty>::_Iterator<_Secure_validation>,bool(__cdecl *)(std::list<_Ty>::_Iterator<_Secure_validation>)>(_FwdIt,_FwdIt,_Pr)' being compiled
1> with
1> [
1> _FwdIt=std::list<connection1>::_Iterator<true>,
1> _Ty=connection1,
1> _Secure_validation=true,
1> _Pr=bool (__cdecl *)(std::list<connection1>::_Iterator<true>)
1> ]
1>c:\program files\microsoft visual studio 9.0\vc\include\algorithm(1241) : error C2664: 'bool (std::list<_Ty>::_Iterator<_Secure_validation>)' : cannot convert parameter 1 from 'connection1' to 'std::list<_Ty>::_Iterator<_Secure_validation>'
1> with
1> [
1> _Ty=connection1,
1> _Secure_validation=true
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(4951) : see reference to function template instantiation '_OutIt std::_Remove_copy_if<std::list<_Ty>::_Iterator<_Secure_validation>,_OutIt,bool(__cdecl *)(std::list<_Ty>::_Iterator<true>)>(_InIt,_InIt,_OutIt,_Pr,std::_Range_checked_iterator_tag)' being compiled
1> with
1> [
1> _OutIt=std::list<connection1>::_Iterator<true>,
1> _Ty=connection1,
1> _Secure_validation=false,
1> _InIt=std::list<connection1>::_Iterator<false>,
1> _Pr=bool (__cdecl *)(std::list<connection1>::_Iterator<true>)
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(1311) : see reference to function template instantiation '_OutIt stdext::unchecked_remove_copy_if<std::list<_Ty>::_Iterator<_Secure_validation>,_FwdIt,bool(__cdecl *)(std::list<_Ty>::_Iterator<_Secure_validation>)>(_InIt,_InIt,_OutIt,_Pr)' being compiled
1> with
1> [
1> _OutIt=std::list<connection1>::_Iterator<true>,
1> _Ty=connection1,
1> _Secure_validation=true,
1> _FwdIt=std::list<connection1>::_Iterator<true>,
1> _InIt=std::list<connection1>::_Iterator<true>,
1> _Pr=bool (__cdecl *)(std::list<connection1>::_Iterator<true>)
1> ]
Similar
Эксперт
41792 / 34177 / 6122
Регистрация: 12.04.2006
Сообщений: 57,940
29.09.2010, 00:09     STL и функция remove_if
Посмотрите здесь:

C++ STL list. Какая функция ищет указатель на элемент равный а ?
C++ vector и функция read() из STL
Метод remove_if STL C++
stl цикл и функция C++
C++ Шаблонная функция вывода для любого stl контейнера
C++ stl remove своя функция
Remove_if - при передаче функции класса выдает ошибки C++
C++ Remove_if для std::list

Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума.
gooseim
Эксперт C++
500 / 404 / 35
Регистрация: 23.09.2010
Сообщений: 1,139
29.09.2010, 00:53     STL и функция remove_if #2
C++
1
2
3
4
5
6
7
8
9
bool cond_comp(const computer1& x)
{
        return (x.comp_mark==1);
}
 
bool cond_conn(const computer1& y)
{
        return (y.conn_mark==1);
}
Yandex
Объявления
29.09.2010, 00:53     STL и функция remove_if
Ответ Создать тему
Опции темы

Текущее время: 02:40. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Рейтинг@Mail.ru