KeyValuePair 클래스를 만들고 관계 연산자를 오버로드 할 때 문제가 발생합니다. 여기 템플릿 기반 클래스에서 관계 연산자 오버로드 (C++)
template <typename K, typename V>
class KeyValuePair
{
public:
//factory
static KeyValuePair<K,V>* newKeyValuePair(K key, V value);
//getters
const K &Key() const;
const V &Value() const;
//setter
V &Value();
//The problem
bool operator<(const KeyValuePair<K,V> &rhs);
string toString();
~KeyValuePair(void);
private:
K key;
V value;
KeyValuePair(K key, V value);
KeyValuePair(void);
};
이 < 함수의 정의입니다 : 이것이 (I 정렬 값을 기준으로 한 것을 시도하고있다) 여기
가 헤더 인 표준 정렬 기능을 사용하기 위해 필요하다는 것을 나의 이해이다
template <typename K, typename V>
bool KeyValuePair<K,V>::operator<(const KeyValuePair<K,V> &rhs)
{
return value < rhs.Value();
}
그리고 여기서 클래스의 기능을 테스트하는 곳입니다.
int _tmain(int argc, _TCHAR* argv[])
{
KeyValuePair<char,int>* kvp1 = KeyValuePair<char, int>::newKeyValuePair('A',1);
KeyValuePair<char,int>* kvp2 = KeyValuePair<char,int>::newKeyValuePair('B',10);
cout << (kvp1 < kvp2) << "\n";
return 0;
}
나는 나의 KeyValuePair 클래스에서 < 함수에서 중단 점을 가지고 있고, 그것은 활성화되지 않습니다.
어떤 아이디어? 미리 감사드립니다.
감사합니다. Dictionary 클래스에서 KeyValuePair를 포인터로 사용하여 쓰기 쉽도록했습니다. 하지만 당신의 요점을 봅니다. 나는 또한 std :: pair에 대해 몰랐다. 나는 그것을 들여다 볼 것이다. – Jake