I am using an std::set to hold members of type Board, and I want to iterate over the set to do comparisons that will not work with the find method as different criteria will be used for sorting verses locating.
1>c:\...\project.cpp(1140): error C2440: 'initializing' : cannot convert from 'std::_Tree_const_iterator<_Mytree>' to 'std::_Tree_const_iterator<_Mytree>'
1> with
1> [
1> _Mytree=std::_Tree_val<std::_Tset_traits<Board,std::greater<Board>,std::allocator<Board>,false>>
1> ]
1> and
1> [
1> _Mytree=std::_Tree_val<std::_Tset_traits<Board,std::less<Board>,std::allocator<Board>,false>>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
the thing is the iterator should not be const. the method is not const, the set is created local to the method, and I do not preface the iterator as const.
Thing::Thing thisFunction(int action){
// snip
set<Board, less<Board>> openSet;
// snip
for(set<Board>::iterator ii = openSet.begin(); // line 1140
ii != openSet.end(); ii++){
// snip
}
this does not make direct sense as the iterator is not declared const so it should not be trying to even consider const.
separately why is the compiler talking about a std::_tree when I am using a std::set
The problem is relatively simple, you cannot assign a
to a
because that is actually a
The standard does not guarantee that these are the same type, and it is not guaranteed that there will be a conversion between them. In practice, these are always different types, and there is no conversion. Thus your error.