C++HashMap 에 대한 약간의 사고
3619 단어 c/c++
hash 사용 시map 에서 헤더 파일 의 인용 방식 은...
#include
#include "HASH_MAP_HPP.h"
using namespace __gnu_cxx;
string 을 key 로 할 때 다음 과 같은 오류 가 발생 합 니 다.
error: no match for call to ‘(const hasher {aka const __gnu_cxx::hash<:__cxx11::basic_string> >}) (const key_type&)’|
\#\#\#\#솔 루 션,아래 헤더 파일 HASH 추가MAP_HPP.h 면 됩 니 다.
#ifndef HASH_MAP_HPP_H_INCLUDED
#define HASH_MAP_HPP_H_INCLUDED
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#if defined(_STLPORT_VERSION)
#include
#include
using std::hash;
using std::hash_map;
using std::hash_set;
#else // not using STLPORT
#ifdef __GNUC__
#if __GNUC__ >= 3
#include
#include
namespace __gnu_cxx {
template <>
struct hash<:string> {
size_t operator()(const std::string& s) const {
unsigned long __h = 0;
for (unsigned i = 0;i < s.size();++i)
__h ^= (( __h << 5) + (__h >> 2) + s[i]);
return size_t(__h);
}
};
}
using __gnu_cxx::hash_map;
using __gnu_cxx::hash;
#else // GCC 2.x
#include
#include
namespace std {
struct hash<:string> {
size_t operator()(const std::string& s) const {
unsigned long __h = 0;
for (unsigned i = 0;i < s.size();++i)
__h ^= (( __h << 5) + (__h >> 2) + s[i]);
return size_t(__h);
}
};
};
using std::hash_map;
using std::hash_set;
using std::hash;
#endif // end GCC >= 3
#elif defined(_MSC_VER) && ((_MSC_VER >= 1300) || defined(__INTEL_COMPILER))
// we only support MSVC7+ and Intel C++ 8.0
#include
#include
namespace stdext {
inline size_t hash_value(const std::string& s) {
unsigned long __h = 0;
for (unsigned i = 0;i < s.size();++i)
__h ^= (( __h << 5) + (__h >> 2) + s[i]);
return size_t(__h);
}
}
using std::hash_map; // _MSC_EXTENSIONS, though DEPRECATED
using std::hash_set;
#else
#error unknown compiler
#endif //GCC or MSVC7+
#endif // end STLPORT
#endif /* ifndef HASH_MAP_HPP */
발생 원인 은 SGI STL 에서 다음 과 같은 hash 함 수 를 제공 합 니 다.
struct hash
struct hash
struct hash
struct hash
struct hash
struct hash
struct hash
struct hash
struct hash
struct hash
struct hash
즉,키 가 상기 유형의 하 나 를 사용한다 면,결 성 된 hash 함 수 를 사용 할 수 있 습 니 다.물론 당신 자신 도 자신의 hash 함 수 를 정의 할 수 있 습 니 다.사용자 정의 변수 에 대해 서 만 이 럴 수 있 습 니 다.예 를 들 어 string 에 대해 서 는 hash 함 수 를 사용자 정의 해 야 합 니 다.
참조 페이지 1 참조 페이지 2
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
3. 배열 의 성명 및 초기 화 (test 1. java)먼저 배열 의 신청, 배열 의 초기 화, 배열 의 복사 등 을 배 웠 습 니 다.배열 에 대해 저 는 C \ C + + 의 배열 과 큰 차이 가 없다 고 생각 합 니 다. 그러나 JAVA 에서 JAVA 는 대상 을 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.