Google 해 스맵 해시 맵 라이브러리로 작업하고 있습니다.클래스 public 멤버 함수를 템플릿 매개 변수로 전달하는 방법은 무엇입니까?
class my_hashmap_key_class {
private:
unsigned char *pData;
int data_length;
public:
// Constructors,Destructor,Getters & Setters
//equal comparison operator for this class
bool operator()(const hashmap_key_class &rObj1, const hashmap_key_class &rObj2) const;
//hashing operator for this class
size_t operator()(const hashmap_key_class &rObj) const;
};
가 지금은 HashFcn
dense_hash_map
에 같은 Key
으로 EqualKey
로 my_hashmap_key_class::operator()(const hashmap_key_class &rObj1, const hashmap_key_class &rObj2)
및 my_hashmap_key_class::operator()(const hashmap_key_class &rObj)
을 my_hashmap_key_class
을 전달하려는 :로
template <class Key, class T,
class HashFcn = std::tr1::hash<Key>,
class EqualKey = std::equal_to<Key>,
class Alloc = libc_allocator_with_realloc<std::pair<const Key, T> > >
class dense_hash_map {
.....
typedef dense_hashtable<std::pair<const Key, T>, Key, HashFcn, SelectKey,
SetKey, EqualKey, Alloc> ht;
.....
};
지금은 정의 내 자신의 클래스 : 그리고 나는 다음과 같은 클래스 템플릿을 클래스를 매개 변수로 사용할 때 다음과 같이 주 함수에서 사용합니다.
main.cpp :
dense_hash_map<hashmap_key_class, int, ???????,???????> hmap;
클래스 매개 변수 함수를 템플릿 매개 변수로 전달하는 적절한 방법은 무엇입니까 ??
내가 좋아하는 통과 시도 :dense_hash_map<hashmap_key_class, int, hashmap_key_class::operator(const hashmap_key_class &rObj1, const hashmap_key_class &rObj2),hashmap_key_class::operator()(const hashmap_key_class &rObj)> hmap;
그러나 운영자가 감지되지 않는 나는 컴파일 오류가 발생합니다. 내가 잘못하고있는 곳을 깨닫도록 도와주세요.
나는 그 연산자를'정적 인 '것으로 생각한다. 또한 동등한 비교를 위해'operator =='를 사용하지 않으시겠습니까? (여전히 수동으로 정의해야합니다.) – leemes
'static'연산자를 만듭니다. –
또는 클래스가 자체 equality functor라는 사실을 다소 이상하게 여긴다. 그러나 전례가 없으면 단순히'my_hashmap_key_class'를 전달하면된다. 비교를 수행하기 위해 인스턴스가 생성되며 매개 변수 중 하나도 생성 된 비교 자 자체가 될 수 없습니다. 'HashFn' 매개 변수에 대해서도 마찬가지입니다. 나는 그것을 자주 보지 못하지만,이 코드를 정의한 것처럼 아무 것도하지 않아야합니다. 그리고 클래스는 기본 구성을 지원해야합니다 (필자는 가정합니다). – WhozCraig