Hola eferion, gracias por responder, verás, hice lo que me dijiste pero sigue dando error, todo apunta a ManPersonas, te pongo el código y en dónde marcan los errores:
Código C++:
Ver original#include <list> //aqui marca error
#include <algorithm>
#include "Persona.h"
#ifndef CONTRPERSONAS_H
#define CONTRPERSONAS_H
using namespace std;
std::list<Persona>lista;
static int maxIdP = 0;
int getMaxIdP(){
return ++maxIdP;
}
bool check(const Persona& p){
int num_reg = std::count_if(lista.begin(),lista.end(),[&p](const Persona& p2){
return p2.nom == p.nom;
}); //aqui marca error
return num_reg > 0;
}
Persona* getRow(std::string xnom){
Persona* toReturn = NULL; // inicialización de puntero nulo
auto it = std::find_if(lista.begin(),lista.end(),[&xnom](const Persona& p){ //aqui marca error
return p.nom == xnom;
});
if(it != lista.end()) //aqui marca error
toReturn = &(it); // it
return toReturn;
}
Persona* getRow(int xid){
Persona* toReturn = NULL; // inicialización de puntero nulo
auto it = std::find_if(lista.begin(),lista.end(),[&xid](const Persona& p){ //aqui marca error
return p.id == xid;
});
if( it != lista.end()) //aqui marca error
toReturn = &(*it);
return toReturn;
}
bool create(Persona p){
if(check(p)){
return false;
}
else{
lista.push_back(p);
return true;
}
}
bool update(Persona p){ }
if(check(p)){
lista.
remove(p
); //aqui marca error }
}
std::list<Persona> read(){
return lista;
}
#endif /* CONTRPERSONAS_H */
Pero cuando ejecuto, los errores que me saltan son estos:
In file included from crud_per.h:3:0,
from menu_per.h:2,
from main.cpp:3:
ManPersonas.h: In function ‘bool check(const Persona&)’:
ManPersonas.h:15:9: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
});
^
ManPersonas.h:15:10: error: no matching function for call to ‘count_if(std::list<Persona>::iterator, std::list<Persona>::iterator, check(const Persona&)::__lambda0)’
});
^
ManPersonas.h:15:10: note: candidate is:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from ManPersonas.h:2,
from crud_per.h:3,
from menu_per.h:2,
from main.cpp:3:
/usr/include/c++/4.8/bits/stl_algo.h:4647:5: note: template<class _IIter, class _Predicate> typename std::iterator_traits<_Iterator>::difference_type std::count_if(_IIter, _IIter, _Predicate)
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
^
/usr/include/c++/4.8/bits/stl_algo.h:4647:5: note: template argument deduction/substitution failed:
In file included from crud_per.h:3:0,
from menu_per.h:2,
from main.cpp:3:
ManPersonas.h: In substitution of ‘template<class _IIter, class _Predicate> typename std::iterator_traits<_Iterator>::difference_type std::count_if(_IIter, _IIter, _Predicate) [with _IIter = std::_List_iterator<Persona>; _Predicate = check(const Persona&)::__lambda0]’:
ManPersonas.h:15:10: required from here
ManPersonas.h:15:10: error: template argument for ‘template<class _IIter, class _Predicate> typename std::iterator_traits<_Iterator>::difference_type std::count_if(_IIter, _IIter, _Predicate)’ uses local type ‘check(const Persona&)::__lambda0’
});
^
ManPersonas.h:15:10: error: trying to instantiate ‘template<class _IIter, class _Predicate> typename std::iterator_traits<_Iterator>::difference_type std::count_if(_IIter, _IIter, _Predicate)’
ManPersonas.h: In function ‘Persona* getRow(std::string)’:
ManPersonas.h:20:14: error: ‘it’ does not name a type
auto it = std::find_if(lista.begin(),lista.end(),[&xnom](const Persona& p){
^
ManPersonas.h:22:10: error: expected primary-expression before ‘)’ token
});
^
ManPersonas.h:22:10: error: expected ‘;’ before ‘)’ token
ManPersonas.h:23:12: error: ‘it’ was not declared in this scope
if(it != lista.end())
^
ManPersonas.h: In function ‘Persona* getRow(int)’:
ManPersonas.h:29:14: error: ‘it’ does not name a type
auto it = std::find_if(lista.begin(),lista.end(),[&xid](const Persona& p){
^
ManPersonas.h:31:10: error: expected primary-expression before ‘)’ token
});
^
ManPersonas.h:31:10: error: expected ‘;’ before ‘)’ token
ManPersonas.h:32:13: error: ‘it’ was not declared in this scope
if( it != lista.end())
^
In file included from menu_per.h:2:0,
from main.cpp:3:
crud_per.h: In function ‘void updated()’:
crud_per.h:35:7: error: no match for ‘operator=’ (operand types are ‘Persona’ and ‘Persona*’)
p = getRow(xnom);
^
crud_per.h:35:7: note: candidate is:
In file included from ManPersonas.h:3:0,
from crud_per.h:3,
from menu_per.h:2,
from main.cpp:3:
Persona.h:4:8: note: Persona& Persona::operator=(const Persona&)
struct Persona{
^
Persona.h:4:8: note: no known conversion for argument 1 from ‘Persona*’ to ‘const Persona&’
In file included from menu_per.h:2:0,
from main.cpp:3:
crud_per.h: In function ‘void deleted()’:
crud_per.h:75:7: error: no match for ‘operator=’ (operand types are ‘Persona’ and ‘Persona*’)
p = getRow(xnom);
^
crud_per.h:75:7: note: candidate is:
In file included from ManPersonas.h:3:0,
from crud_per.h:3,
from menu_per.h:2,
from main.cpp:3:
Persona.h:4:8: note: Persona& Persona::operator=(const Persona&)
struct Persona{
^
Persona.h:4:8: note: no known conversion for argument 1 from ‘Persona*’ to ‘const Persona&’
In file included from /usr/include/c++/4.8/list:64:0,
from ManPersonas.h:1,
from crud_per.h:3,
from menu_per.h:2,
from main.cpp:3:
/usr/include/c++/4.8/bits/list.tcc: In instantiation of ‘void std::list<_Tp, _Alloc>::remove(const value_type&) [with _Tp = Persona; _Alloc = std::allocator<Persona>; std::list<_Tp, _Alloc>::value_type = Persona]’:
ManPersonas.h:48:27: required from here
/usr/include/c++/4.8/bits/list.tcc:248:17: error: no match for ‘operator==’ (operand types are ‘Persona’ and ‘const value_type {aka const Persona}’)
if (*__first == __value)
^
/usr/include/c++/4.8/bits/list.tcc:248:17: note: candidates are:
In file included from /usr/include/c++/4.8/iosfwd:40:0,
from /usr/include/c++/4.8/ios:38,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.cpp:1:
/usr/include/c++/4.8/bits/postypes.h:216:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
^
Entre otros errores, pero esos son los que me llaman más la atención
¿y ahora? espero sus respuestas y saludos