Ver Mensaje Individual
  #15 (permalink)  
Antiguo 10/03/2016, 17:46
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Respuesta: headers, carpetas y menúes c++

Hola eferion, gracias por responder verás usé un remove_if por lo que me dijiste, pero ahora estoy un poco confundido:

Código C++:
Ver original
  1. #include <algorithm>
  2. #include <list>
  3. #include "Persona.h"
  4. #ifndef CONTRPERSONAS_H
  5. #define CONTRPERSONAS_H
  6. using namespace std;    
  7.     std::list<Persona>lista;
  8.     static int maxIdP = 0;
  9.     int getMaxIdP(){
  10.         return ++maxIdP;
  11.     }
  12.     bool check(const Persona& p){
  13.         int num_reg = std::count_if(lista.begin(),lista.end(),[&p](const Persona& p2){
  14.             return p2.nom == p.nom;
  15.         });
  16.         return num_reg > 0;
  17.     }
  18.     Persona* getRow(std::string xnom){
  19.         Persona* toReturn = NULL; // inicialización de puntero nulo
  20.         auto it = std::find_if(lista.begin,lista.end,[&xnom](const Persona& p){
  21.             return p.nom == xnom;
  22.         }); //esta línea da error - no matching function for call to ....
  23.         if( it != lista.end())
  24.             toReturn = &(it); // it
  25.         return toReturn;
  26.     }
  27.     Persona* getRow(int xid){
  28.         Persona* toReturn = NULL; // inicialización de puntero nulo
  29.         auto it = std::find_if(lista.begin,lista.end,[&xid](const Persona& p){
  30.             return p.id == xid;
  31.         }); //esta línea da error - no matching function for call to ....
  32.         if( it != lista.end())
  33.             toReturn = &(it); // it
  34.         return toReturn;
  35.     }
  36.     bool create(Persona p){
  37.         if(check(p)){            
  38.             return false;
  39.         }
  40.         else{
  41.             lista.push_back(p);
  42.             return true;
  43.         }
  44.     }
  45.     bool update(Persona p){ }
  46.     void deleted(Persona p){
  47.         if(check(p)){
  48.             lista.remove_if(lista.begin(),lista.end(),[&p](const Persona& p2){
  49.                 return p.id == p2.id;
  50.             }); //esta línea da error - no matching function for call to ....
  51.         }
  52.     }
  53.     std::list<Persona> read(){
  54.         return lista;        
  55.     }

Lo raro es que da error cuando cierra paréntesis y llave, otra pregunta ¿hay otra forma para obtener elementos que no sea usando punteros?

Espero sus respuestas y respuestas.