I have a multiset and I'm getting a range from it. I want to add this range in a vector to use it later, this is what I'm doing:
class foo
{
public:
int a;
foo(int a) : a(a){}
};
class FooPointerCompare
{
public:
bool operator()(const foo* a, const foo* b)
{
return a->a < b->a;
}
};
std::multiset<foo*, FooPointerCompare> m;
std::vector<std::multiset<foo*, FooPointerCompare>::iterator> v;
auto pair = m.equal_range(new foo(5)); //leak here, I know
v.insert(v.end(), pair.first, pair.second);
but I get these errors:
No matching constructor for initialization of 'std::__1::__tree_const_iterator<foo *, const std::__1::__tree_node<foo *, void *> *, int>'
No viable overloaded '='
when I use a simple for(auto it = pair.first; it != pair.second; it++) v.push_back(it); it works perfectly. What is wrong with my vector::insert call?
foo f(5); auto pair = m.equal_range(&f);than to write//leak here, I know;-p