Ver Mensaje Individual
  #7 (permalink)  
Antiguo 09/03/2016, 13:26
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, 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
  1. #include <list> //aqui marca error
  2. #include <algorithm>
  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.         }); //aqui marca error
  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){  //aqui marca error
  21.             return p.nom == xnom;
  22.         });    
  23.         if(it != lista.end()) //aqui marca error
  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){ //aqui marca error
  30.             return p.id == xid;
  31.         });    
  32.         if( it != lista.end()) //aqui marca error
  33.             toReturn = &(*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 remove(Persona p){
  47.         if(check(p)){
  48.             lista.remove(p); //aqui marca error
  49.         }
  50.     }
  51.     std::list<Persona> read(){
  52.         return lista;        
  53.     }  
  54. #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