Consider the following class
#include <set>
#include <vector>
using namespace std;
class foo {
public:
struct spatial {
bool block;
char status; // H, M, Z
};
typedef pair< int, vector<spatial> > way; // tag + spatial vector
typedef set< way > one_set;
void bar()
{
way theWay;
theWay.first = 10;
one_set theSet;
one_set::iterator sit = theSet.end();
if (theSet.size() == 16) {
sit = theSet.begin();
}
theSet.insert(sit, theWay);
}
};
For the insert function, I receive these errors and I don’t know what does that mean
error C2784: 'bool std::operator <(const std::vector<_Ty,_Ax> &,const std::vector<_Ty,_Ax> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'const foo::spatial' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility
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 foo::spatial' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility 3144
error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const foo::spatial' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility 3144
error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const foo::spatial' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility 3144
error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const foo::spatial' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility 3144
error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const foo::spatial' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility 3144
error C2676: binary '<' : 'const foo::spatial' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility 3144
Stuck at this point. Appreciate any help.
Your
waytype must have anoperator<defined to be used in anstd::set.std::pairhasoperator<if both types hasoperator<.inthasoperator<, that is ok, butvector<spatial>hasoperator<only if its element type hasoperator<. Yourspatialclass has none and therefore yourwaytypedef has nooperator<as well.Create an
operator<for yourspatialclass and you’re ok.If you think that
spatialclasses should not be comparable but insist on havingwayin a set, you can also create your own comparator (a functor/lambda with twoconst way¶meters that returntrueif the first is less than the second) and pass that as the second template parameter of your set.Anyway, because
std::setstores its elements sorted, to use it you have to define the ordering of your elements at some point.