将对象插入集合中

liv*_*495 1 c++

我想在这样的集合中插入一个向量:

set<vector<prmEdge> > cammini;
vector<prmEdge> vecEdge;
cammini.insert(vecEdge);
Run Code Online (Sandbox Code Playgroud)

我有这样的编译错误:

prmPlanner.cpp:1285:   instantiated from here
/usr/include/c++/4.2/bits/stl_algobase.h:853: error: no match for ‘operator<’ in ‘__first1.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = const prmEdge*, _Container = std::vector<prmEdge, std::allocator<prmEdge> >]() < __first2.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = const prmEdge*, _Container = std::vector<prmEdge, std::allocator<prmEdge> >]()’
/usr/include/c++/4.2/bits/stl_algobase.h:855: error: no match for ‘operator<’ in ‘__first2.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = const prmEdge*, _Container = std::vector<prmEdge, std::allocator<prmEdge> >]() < __first1.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = const prmEdge*, _Container = std::vector<prmEdge, std::allocator<prmEdge> >]()’
make[1]: *** [prmPlanner.o] Errore 1
Run Code Online (Sandbox Code Playgroud)

我该怎么办?有人能帮帮我吗?

非常感谢你

Kir*_*sky 5

它不知道如何比较矢量.你应该提供operator<vector<prmEdge>(或prmEdge自动使用std::lexicographical_compare的载体),或使用unordered_set,如果你实际上并不需要有序集合向量.

  • @Fred Larson,它使用`std :: lexicographical_compare`进行比较,所以应该为`prmEdge`定义`operator <`. (2认同)