I am using a custom Set class that is basically the same as the STL Set class
The problem is that I am somehow implementing it incorrectly and the default comparison function is used rather than a comparison I defined.
Set<Lexicon::CorrectionT> Lexicon::suggestCorrections(Lexicon::MatchesT & matchSet)
{
Set<CorrectionT> suggest(compareCorr); //ordered Set
suggestCorrectionsHelper(root, suggest, 0, matchSet.testWord, 0, matchSet.testTime);
return suggest;
}
int compareCorr(Lexicon::CorrectionT a, Lexicon::CorrectionT b)
{
if (a.editDistance < b.editDistance)
return -1;
else if (a.editDistance == b.editDistance)
return 0;
else
return 1;
}
struct CorrectionT {
int editDistance; //stackItems
string suggestedWord; //stackItems
};
Some research:
- The class library
- An issue with the same class – suggested that the STL Set class is used, in this case I might still need help understanding how to define the comparison function, so posting question
I have 19 C2784 errors all relating to some form of “error C2784: ‘bool std::operator ==(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)’ : could not deduce template argument for ‘const std::_Tree<_Traits> &’ from ‘Lexicon::CorrectionT’
and referencing this code
template <typename Type>
int OperatorCmp(Type one, Type two) {
if (one == two) return 0;
if (one < two) return -1;
return 1;
}
My question: how do you suggest correcting this?
Attempt at changing default definition type:
#include "lexicon.h"
//template <typename Type>
int OperatorCmp(Lexicon::CorrectionT one, Lexicon::CorrectionT two) {
if (one.editDistance == two.editDistance) return 0;
if (one.editDistance < two.editDistance) return -1;
return 1;
}
#endif
The comparison function for STL
setmust be a Strict Weak Ordering, so that class is not the same as an STLset.The error indicates the default
OperatorCmpis being used, I don’t know why, but you could make that default one work by definingoperator<andoperator==for yourCorrectionTtype.