1. Este site usa cookies. Ao continuar a usar este site está a concordar com o nosso uso de cookies. Saber Mais.

hash_set C++

Discussão em 'Programação' iniciada por OubeLa, 30 de Novembro de 2007. (Respostas: 1; Visualizações: 1330)

  1. OubeLa

    OubeLa Power Member

    Tenho uma classe Trabalhador, e depois tenho uma classe Cantina. Na classe cantina tenho um membro private

    Código:
    vector<Trabalhador> trabalhadores
    Agora tenho de guardar os trabalhadores numa hash table (hash_set)

    Quando tento fazer

    Código:
    #include <hash_set>
    //...
    using namespace stdext; //stdext::hash_set em MS Visual Studio
    //using namespace __gnu_cxx; com compilador g++
    //...
    hash_set<Trabalhador> trabalhadores //claro que neste momento ja nao tenho o vector
    
    dá erro ao criar a hash_set com type Trabalhador. Eu já percebi +/- o porquê do erro, só não sei como o ultrapassar.

    Código:
    #ifndef TRABALHADOR_H_
    #define TRABALHADOR_H_
    
    #include <string>
    #include <vector>
    
    #include "Data.h"
    
    using namespace std;
    
    class Trabalhador
    {
        string nome; //nome do trabalhador
        string cargo; //cargo do trabalhador
        unsigned int codigo; //codigo do trabalhador
        unsigned int turno;    //turno é um int: 1 para almoço, 2 para jantar, 0 para sem turno
        vector<Data> datas;
    
    public:
        Trabalhador(string, string);
        void setTurno(unsigned int);
        unsigned int getTurno() const;
        void setCodigo(unsigned int num_funcionarios);
        unsigned int getCodigo() const;
        string getNome() const;
        string getCargo() const;
        bool cargoValido();
        void getInfo();
        void colocaData(Data);
        void getData(Data);
        virtual ~Trabalhador();
    };
    
    #endif /*TRABALHADOR_H_*/
    Aqui está a classe Trabalhador.

    E aqui o erro
    Código:
    1>------ Build started: Project: Cantina 2, Configuration: Debug Win32 ------
    1>Compiling...
    1>Cantina.cpp
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::queue<_Ty,_Container> &,const std::queue<_Ty,_Container> &)' : could not deduce template argument for 'const std::queue<_Ty,_Container> &' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\queue(103) : see declaration of 'std::operator <'
    1>        c:\program files\microsoft visual studio 8\vc\include\functional(142) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
    1>        with
    1>        [
    1>            _Ty=Trabalhador
    1>        ]
    1>        c:\program files\microsoft visual studio 8\vc\include\xhash(112) : see reference to class template instantiation 'std::less<_Ty>' being compiled
    1>        with
    1>        [
    1>            _Ty=Trabalhador
    1>        ]
    1>        c:\program files\microsoft visual studio 8\vc\include\hash_set(60) : see reference to class template instantiation 'stdext::hash_compare<_Kty,_Pr>' being compiled
    1>        with
    1>        [
    1>            _Kty=Trabalhador,
    1>            _Pr=std::less<Trabalhador>
    1>        ]
    1>        c:\program files\microsoft visual studio 8\vc\include\xhash(119) : see reference to class template instantiation 'stdext::_Hset_traits<_Kty,_Tr,_Alloc,_Mfl>' being compiled
    1>        with
    1>        [
    1>            _Kty=Trabalhador,
    1>            _Tr=stdext::hash_compare<Trabalhador,std::less<Trabalhador>>,
    1>            _Alloc=std::allocator<Trabalhador>,
    1>            _Mfl=false
    1>        ]
    1>        c:\program files\microsoft visual studio 8\vc\include\hash_set(69) : see reference to class template instantiation 'stdext::_Hash<_Traits>' being compiled
    1>        with
    1>        [
    1>            _Traits=stdext::_Hset_traits<Trabalhador,stdext::hash_compare<Trabalhador,std::less<Trabalhador>>,std::allocator<Trabalhador>,false>
    1>        ]
    1>        e:\documents and settings\ei06118\desktop\cantina 2\cantina 2\cantina.h(27) : see reference to class template instantiation 'stdext::hash_set<_Kty>' being compiled
    1>        with
    1>        [
    1>            _Kty=Trabalhador
    1>        ]
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Alloc> &' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\deque(1327) : see declaration of 'std::operator <'
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\list(1274) : see declaration of 'std::operator <'
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\vector(1276) : see declaration of 'std::operator <'
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\string(151) : see declaration of 'std::operator <'
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\string(141) : see declaration of 'std::operator <'
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\string(131) : see declaration of 'std::operator <'
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\xutility(1842) : see declaration of 'std::operator <'
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const Trabalhador'
    1>        c:\program files\microsoft visual studio 8\vc\include\utility(76) : see declaration of 'std::operator <'
    1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2676: binary '<' : 'const Trabalhador' does not define this operator or a conversion to a type acceptable to the predefined operator
    1>Build log was saved at "file://e:\Documents and Settings\ei06118\Desktop\Cantina 2\Cantina 2\Debug\BuildLog.htm"
    1>Cantina 2 - 10 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    
    Já percebi que tenho que criar uma classe ou estrutura para função hash, mas não estou a conseguir. Se me puderem ajudar, agradecia :)
     
    Última edição: 30 de Novembro de 2007
  2. OubeLa

    OubeLa Power Member

    Alguém me pode ajudar? :rolleyes:
     

Partilhar esta Página