c++ - error in handling set of vectors -


i'm new standard template library , wanted store overlapping subsequences. since set ignores duplicates. have set of vectors:

set<vector<int> > subsequences; 

but when try insert set:

sort(arr.begin(), arr.end()); subsequences.insert(arr); 

i error:

coinchange.cpp:20:18: error: no matching member function call 'insert'     subsequences.insert(arr);     ~~~~~~~~~~~~~^~~~~~ /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../include/c++/v1/set:596:25: note:       candidate function not viable: no known conversion 'vector<long long, allocator<long       long>>' 'const vector<int, allocator<int>>' 1st argument     pair<iterator,bool> insert(const value_type& __v)                         ^ /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../include/c++/v1/set:613:14: note:       candidate function template not viable: requires 2 arguments, 1 provided         void insert(_inputiterator __f, _inputiterator __l)              ^ /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../include/c++/v1/set:604:14: note:       candidate function not viable: requires 2 arguments, 1 provided     iterator insert(const_iterator __p, const value_type& __v)          ^ 

since i'm new stl, not able understand i'm doing wrong. please help.

given error, more declared std::vector<long, long> , assumed compatible std::vector<int>. not case.

if t , u different types, std::vector<t> , std::vector<u> different types. in case t int, , u long long.

the following code compiles correctly:

#include <set> #include <vector> #include <algorithm>  using namespace std;  int main()  {     std::set<vector<int> > subsequences;         std::vector<int> arr;     std::sort(arr.begin(), arr.end());     subsequences.insert(arr); } 

while following code produces errors you're seeing:

#include <set> #include <vector> #include <algorithm>  using namespace std;  int main()  {     std::set<vector<int> > subsequences;         std::vector<long long> arr;     std::sort(arr.begin(), arr.end());     subsequences.insert(arr); } 

so obvious fix make sure you're using same types. 1 way ensure use typedef, , make sure used in code base denote vector type use:

//... typedef std::vector<int> intvector;  // change long long if needed //... std::set<intvector> subsequences; intvector arr; //... 

Comments