Ver Mensaje Individual
  #13 (permalink)  
Antiguo 16/09/2016, 05:19
dehm
 
Fecha de Ingreso: septiembre-2010
Mensajes: 494
Antigüedad: 13 años, 7 meses
Puntos: 10
Respuesta: Qt.QTableView. Varias dudas

Cita:
Iniciado por eferion Ver Mensaje
Pon un ejemplo del código que reproduzca el problema :)
Perdón, no lo había puesto porque prácticamente es una copia de lo que mas puesto:

Esto me funciona:
Código C++:
Ver original
  1. #include <iostream>
  2. #include <map>
  3.  
  4.  
  5. enum class Sexo
  6. {
  7.     undefined, male, female
  8. };
  9.  
  10. using IconsMap = std::map<Sexo,std::string>;
  11.  
  12. IconsMap initMap()
  13. {
  14.     return
  15.     {
  16.         std::make_pair(Sexo::undefined,"No definido"),
  17.         std::make_pair(Sexo::male,"Niño"),
  18.         std::make_pair(Sexo::female,"Niña")
  19.     };
  20. }
  21.  
  22. class IconoWareHouse
  23. {
  24.  
  25. private:
  26.     static IconsMap _icons;
  27.  
  28. public:
  29.     IconoWareHouse()=delete;//no debe haber constructor disponible al ser clase estática
  30.     static std::string GetIcon(Sexo type)
  31.     {
  32.         auto it = _icons.find(type);
  33.         if(it == _icons.end())
  34.         {
  35.             it = _icons.find(Sexo::undefined);
  36.         }
  37.         return it->second;
  38.     }
  39. };
  40.  
  41. IconsMap IconoWareHouse::_icons(initMap());
  42.  
  43.  
  44. int main()
  45. {
  46.     std::cout<<IconoWareHouse::GetIcon(Sexo::female)<<std::endl;
  47.     return 0;
  48. }

Pero esto no:
Código C++:
Ver original
  1. #include <iostream>
  2. #include <map>
  3.  
  4.  
  5. enum class Sexo
  6. {
  7.     undefined, male, female
  8. };
  9.  
  10. using IconsMap = std::map<Sexo,std::string>;
  11.  
  12. class IconoWareHouse
  13. {
  14.  
  15. private:
  16.     static IconsMap _icons;
  17.  
  18. public:
  19.     IconoWareHouse()=delete;//no debe haber constructor disponible al ser clase estática
  20.     static std::string GetIcon(Sexo type)
  21.     {
  22.         auto it = _icons.find(type);
  23.         if(it == _icons.end())
  24.         {
  25.             it = _icons.find(Sexo::undefined);
  26.         }
  27.         return it->second;
  28.     }
  29.     IconsMap initMap()
  30.     {
  31.         return
  32.         {
  33.             std::make_pair(Sexo::undefined,"No definido"),
  34.             std::make_pair(Sexo::male,"Niño"),
  35.             std::make_pair(Sexo::female,"Niña")
  36.         };
  37.     }
  38. };
  39.  
  40. IconsMap IconoWareHouse::_icons(initMap());
  41.  
  42.  
  43. int main()
  44. {
  45.     std::cout<<IconoWareHouse::GetIcon(Sexo::female)<<std::endl;
  46.     return 0;
  47. }

En este segundo caso me da este error:

error: cannot call member function ‘IconsMap IconoWareHouse::initMap()’ without object
__________________
Mi calculadora en Qt