I try to fill the m_theDefinitions atribute on class CDefinitionContainer.
the CDefinitionContainer.h
the the CDefinitionContainer.cpp
the definitionhasher.h
and the definition class looks so:
I become the error:
c:\Documents and Settings\My Documents\Visual Studio Projects\hashing\CDefinitionContainer.cpp(67): error C2676: binary '<' : 'iter_def' does not define this operator or a conversion to a type acceptable to the predefined operator
the error refers to the function
on the CDefinitionContainer.cpp File
the CDefinitionContainer.h
Code:
#include <iostream>
#include <string>
#include <vector>
#include "string_hasher.h" // with included <hash_set>
class CDefinition;
class CDefinitionContainer {
public:
CDefinitionContainer();
void addDefinition(std::string,unsigned short);
void dump(void);
private:
stdext::hash_set<CDefinition*,definitionhasher> m_theDefinitions;
};
#endif //CDEFINITIONCONTAINER_H
the the CDefinitionContainer.cpp
Code:
#include "CDefinition.h"
using namespace std;
using namespace stdext;
typedef hash_set<CDefinition*,definitionhasher>::iterator iter_def;
void CDefinitionContainer::addDefinition(string N,unsigned short SiV){
m_theDefinitions.insert(new CDefinition(N,SiV)));
}
void CDefinitionContainer::dump(){
for(iter_def i = m_theDefinitions.begin() ;i < m_theDefinitions.end(); ++i)
(*i)->dump();
}
the definitionhasher.h
Code:
#define DEFINITION_HASHER_H
#include <hash_set>
#include <string>
#include "CDefinition.h"
class definitionhasher : public
stdext::hash_compare<CDefinition*>
{
public:
size_t operator() (const CDefinition* &s) const{
size_t h = 0;
std::string::const_iterator p, p_end;
for(p = s->m_strSymbolName.begin(), p_end = s->m_strSymbolName.end(); p != p_end; ++p)
{
h = 31 * h + (*p);
}
return h;
}
bool operator() (const CDefinition* &s1, const CDefinition* &s2) const
{
return s1->m_strSymbolName < s2->m_strSymbolName;
}
};
#endif
and the definition class looks so:
Code:
#ifndef CDEFINITION_H
#define CDEFINITION_H
#include <iostream>
#include <string>
class CDefinition {
protected:
friend class definitionhasher;
std::string m_strSymbolName;
public:
~CDefinition();
CDefinition(std::string, unsigned short);
bool operator<( CDefinition const& a){
return this->m_strSymbolName < a.m_strSymbolName ;}
void dump(void);
};
#endif //CDEFINITION_H
I become the error:
c:\Documents and Settings\My Documents\Visual Studio Projects\hashing\CDefinitionContainer.cpp(67): error C2676: binary '<' : 'iter_def' does not define this operator or a conversion to a type acceptable to the predefined operator
the error refers to the function
Code:
void CDefinitionContainer::dump(){
for(iter_def i = m_theDefinitions.begin() ;i < m_theDefinitions.end(); ++i)
(*i)->dump();