Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

utilisation des hash_set pour les objets

1 réponse
Avatar
ckadi-nospam
Bonjour,

Je suis sous linux Mandarake 8.2 et je souhaite utiliser les hashtables
pour y mettre des objets autre que les types de base.

lors de l'utilisationde hash_set, le compilateur me rejette avec les
erreurs suivantes :

g++ -DHAVE_CONFIG_H -I. -I. -I.. -O2 -fno-exceptions -fno-check-new -c
contextsession.cpp

In file included from /usr/include/c++/3.2/backward/hash_set.h:59,
from contextsession.cpp:27:
/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning
This file includes at least one deprecated or antiquated header. Please
consider using one of the 32 headers found in section 17.4.1.2 of the
C++ standard. Examples include substituting the <X> header for the <X.h>
header for C++ includes, or <sstream> instead of the deprecated header
<strstream.h>. To disable this warning use -Wno-deprecated.
/usr/include/c++/3.2/bits/stl_function.h: In instantiation of
`std::_Identity<const ContextSession>':
/usr/include/c++/3.2/ext/stl_hashtable.h:266: instantiated from
`__gnu_cxx::hashtable<const ContextSession, const ContextSession,
__gnu_cxx::hash<const ContextSession>, std::_Identity<const
ContextSession>, equalsCTX, std::allocator<const ContextSession> >'
/usr/include/c++/3.2/ext/hash_set:107: instantiated from
`__gnu_cxx::hash_set<const ContextSession, __gnu_cxx::hash<const
ContextSession>, equalsCTX, std::allocator<const ContextSession> >'
contextsession.cpp:210: instantiated from here
/usr/include/c++/3.2/bits/stl_function.h:481: `const _Tp&
std::_Identity<_Tp>::operator()(const _Tp&) const [with _Tp = const
ContextSession]' and `_Tp& std::_Identity<_Tp>::operator()(_Tp&) const
[with _Tp = const ContextSession]' cannot be overloaded
/usr/include/c++/3.2/bits/stl_alloc.h: In instantiation of
`std::allocator<const ContextSession>':
/usr/include/c++/3.2/ext/hash_set:130: instantiated from
`__gnu_cxx::hash_set<_Value, _HashFcn, _EqualKey, _Alloc>::hash_set()
[with _Value = const ContextSession, _HashFcn = __gnu_cxx::hash<const
ContextSession>, _EqualKey = equalsCTX, _Alloc = std::allocator<const
ContextSession>]'
contextsession.cpp:210: instantiated from here
/usr/include/c++/3.2/bits/stl_alloc.h:636: `const _Tp*
std::allocator<_Alloc>::address(const _Tp&) const [with _Tp = const
ContextSession]' and `_Tp* std::allocator<_Alloc>::address(_Tp&) const
[with _Tp = const ContextSession]' cannot be overloaded
gmake: *** [contextsession.o] Erreur 1
*** échec ***

1 réponse

Avatar
ckadi-nospam
Bonjour,

J'ai finalement utilise les hash-map qui gere les objets.
pou que ca marche:

il faut creer un typedef :

typedef hash_map<const char*, Obj hash<const char* >, equalsString> TObject;

creer une varibale pour le type d'objets a gerer :
TObject; liste_obj;


ensuite, il faut declarer un iterateur :
TObject::iterator iter=liste_obj.find(key);




wrote:
ckadi-nospam wrote in message
news:<bfm57o$5sh$...


Je suis sous linux Mandarake 8.2 et je souhaite utiliser les
hashtables pour y mettre des objets autre que les types de base.



lors de l'utilisationde hash_set, le compilateur me rejette avec les
erreurs suivantes :



Ça aurait aidé si tu avais fourni le code qui a déclenché l'erreur. Mais
à juger d'après les messages d'erreur, tu as essayé à utiliser un :

__gnu_cxx::hash_set< ContextSession const >

Ça ne marche pas. Le contenu d'un hash_set sont toujours const, et
l'implémentation utilise d'autres éléments qui surcharge sur le const.
Il suffit de faire :

__gnu_cxx::hash_set< ContextSession >

En général, la norme ne permet pas l'instantiation d'une collection sur
un type const.

--
James Kanze GABI Software mailto:
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16