Respuesta: Ayuda con Funciones objeto (funtores) Ya he hecho los cambios que comentastes en los funtores:
Código:
struct funtor_findif {
funtor_findif(const string &n) : name(n) {}
bool operator()(pokemon &p1) {
if( name==p1.dame_nombre() ) return true;
else return false;
}
string name;
};
struct funtor_accutotales {
map<string,int> operator() (map<string,int> &acum, pokemon &p1) { // Epera el valor actual del acumulador, y el elemento que toca ahora en la nueva suma, con esto decides tu la nueva suma
pair<string,string> aux=p1.dame_tipos();
acum[aux.first]++;
if ( aux.second != "" ) {
acum[aux.second]++;
}
acum["Total"]++;
return acum;
}
};
struct funtor_accutipos {
set<string> operator() (set<string> &acum, pokemon &p1) {
pair<string,string> aux=p1.dame_tipos();
acum.insert(acum.begin(),aux.first);
if ( aux.second != "" ) {
acum.insert(acum.begin(),aux.second);
}
return acum;
}
};
struct funtor_accudetipo {
public:
funtor_accudetipo(const string &t) : tipo(t) {}
vector<pokemon> operator() (vector<pokemon> &acum, pokemon &p1) {
pair<string,string> aux=p1.dame_tipos();
if (aux.first==tipo) acum.push_back(p1);
if (aux.second==tipo) acum.push_back(p1);
return acum;
}
string tipo;
};
y el compilador: Cita: /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_numeric.h: In function ‘_Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation) [with _InputIterator = std::_Rb_tree_const_iterator<pokemon>, _Tp = std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >, _BinaryOperation = funtor_accutotales]’: pokedex.cc:70: instantiated from here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_numeric.h:116: error: no hay coincidencia para la llamada a ‘(funtor_accutotales) (std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >&, const pokemon&)’
pokedex.cc:14: nota: los candidatos son: std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > > funtor_accutotales::operator()(std::map<std::basic _string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >&, pokemon&)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_numeric.h: In function ‘_Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation) [with _InputIterator = std::_Rb_tree_const_iterator<pokemon>, _Tp = std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, _BinaryOperation = funtor_accutipos]’: pokedex.cc:75: instantiated from here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_numeric.h:116: error: no hay coincidencia para la llamada a ‘(funtor_accutipos) (std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, const pokemon&)’
pokedex.cc:26: nota: los candidatos son: std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > funtor_accutipos::operator()(std::set<std::basic_s tring<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, pokemon&)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_numeric.h: In function ‘_Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation) [with _InputIterator = std::_Rb_tree_const_iterator<pokemon>, _Tp = std::vector<pokemon, std::allocator<pokemon> >, _BinaryOperation = funtor_accudetipo]’: pokedex.cc:80: instantiated from here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_numeric.h:116: error: no hay coincidencia para la llamada a ‘(funtor_accudetipo) (std::vector<pokemon, std::allocator<pokemon> >&, const pokemon&)’
pokedex.cc:39: nota: los candidatos son: std::vector<pokemon, std::allocator<pokemon> > funtor_accudetipo::operator()(std::vector<pokemon, std::allocator<pokemon> >&, pokemon&)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function ‘_InputIterator std::__find_if(_InputIterator, _InputIterator, _Predicate, std::input_iterator_tag) [with _InputIterator = std::_Rb_tree_const_iterator<pokemon>, _Predicate = funtor_findif]’:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:338: instantiated from ‘_InputIterator std::find_if(_InputIterator, _InputIterator, _Predicate) [with _InputIterator = std::_Rb_tree_const_iterator<pokemon>, _Predicate = funtor_findif]’ pokedex.cc:54: instantiated from here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:188: error: no hay coincidencia para la llamada a ‘(funtor_findif) (const pokemon&)’
pokedex.cc:6: nota: los candidatos son: bool funtor_findif::operator()(pokemon&)
|