the code below produces compiler error C2784:
‘bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)’ : could not deduce template argument for ‘const std::_Tree<_Traits> &’ from ‘const std::_Tree_iterator<_Mytree>’
What is wrong with the code? Many thanks in advance; I couldn’t find any posts on that error message that would help me.
#include <map>
#include <set>
void main(){
int i=1;
std::map<int, int> A;
A[i]=i;
std::set<std::map<int, int>::iterator > setOfIts;
setOfIts.insert(A.begin());
}
What you’re seeing is Visual Studio’s long way of complaining it has no way to compare the iterators you’d like to place in the set, because there’s no appropriate
operator <. And since it can’t compare them, it can’t decide whether two iterators have the same value, hence only one of them should be in the set.To fix the problem, you can provide a less then operator of your own – see example here. What would be the meaning of iterators equality is up to you to figure out…