0
struct Cord
    {
        int x_cord;
        int y_cord;
        Cord(int x = 0,int y = 0):x_cord(x),y_cord(y) {}
        bool operator < (const Cord& cord) const
        {
            if (x_cord == cord.x_cord)
            {
                return y_cord < cord.y_cord;
            }
            return x_cord < cord.x_cord;
        }
        bool operator == (const Cord& cord) const
        {
            return x_cord == cord.x_cord && y_cord == cord.y_cord;
        }
    };
std::set<Cord> cordRes,cordTmp;//initialized before
std::set<Cord> cordItersect;
std::set_intersection(cordRes.begin(),cordRes.end(),cordTmp.begin(),cordTmp.end(),cordRes.begin(),cordItersect.begin());

The compilation for above code fails.Any proposiotons how to use set_intersection correctly in the example? Thanks

YAKOVM
  • 9,805
  • 31
  • 116
  • 217

1 Answers1

1

Well one problem is that set_intersection only takes five arguments. The other problem is that you need some mechanism to create the elements you are inserting to cordItersect. In your case that would be to use std::inserter.

std::set_intersection(cordRes.begin(), cordRes.end(),
    cordTmp.begin(), cordTmp.end(),
    std::inserter(cordItersect, cordItersect.end()));
john
  • 85,011
  • 4
  • 57
  • 81