functors_sort:vector
<p>I have this class:</p>

<pre><code>class QSweep{

public:
QSweep(const vector&lt; vector&lt;double&gt; &gt;&amp; myPoints, const vector&lt; vector&lt;int&gt; &gt;&amp;myEdges);

void intersection(vector&lt; vector&lt;double&gt; &gt;&amp; myPoints, vector&lt; vector&lt;int&gt; &gt;&amp; myEdges);
vector&lt; vector&lt;int&gt; &gt;* sortEdges(vector&lt; vector&lt;double&gt; &gt;&amp; myPoints,
vector&lt;vector&lt;int&gt;&gt;&amp; myEdges);

bool sortx(const vector&lt; vector&lt;int&gt; &gt;&amp; edge1, const vector&lt; vector &lt;int&gt; &gt;&amp; edge2) {
return edge1[0][0]&lt; edge2[0][0];
};
private:
vector&lt; vector&lt;double&gt; &gt; myPoints_;
vector&lt; vector&lt;int&gt; &gt; myEdges_;
};
</code></pre>

<p>The constructor creates the desired data structure in this way:</p>

<pre><code>QSweep::QSweep(const vector&lt; vector&lt;double&gt; &gt;&amp; myPoints, const vector&lt; vector&lt;int&gt;&gt;&amp;  
myEdges){
myPoints_=vector&lt; vector&lt;double&gt; &gt; (myPoints.size(), vector&lt; double &gt;(3,0));
for (unsigned int i=0;i&lt;myPoints.size();i++){
myPoints_[i][0]=myPoints[i][0];
myPoints_[i][1]=myPoints[i][1];
myPoints_[i][2]=myPoints[i][2];
}

myEdges_=vector&lt; vector&lt;int&gt; &gt; (myEdges.size(), vector&lt; int &gt;(2,0));
for (unsigned int i=0;i&lt;myEdges.size();i++){
myEdges_[i][0]=myEdges[i][0];
myEdges_[i][1]=myEdges[i][1];
}
}
</code></pre>

<p>giving E.g:
myPoints={{1.0,1.0,2.0},{18.0,4.0,2.0},{5.0,1.0,2.0}};
myEdges={{0,1},{1,2},{0,2}};</p>

<p>I want to have a sort function for myEdges 2-dimensional vector depending on the first coordinate of myPoints given by myEdges[i][0].E.g after sorting myEdges would become
myEdges={{0,1},{0,2},{1,2}} because
myPoints[myEdges[1][0]][0]

<p>I tried:</p>

<pre><code> bool sortx(const vector&lt;int&gt; &amp; edge1,const vector&lt;int&gt; &amp; edge2) {
 return myPoints_[edge1[0][0]&lt; myPoints_[edge2[0][0];
 };
</code></pre>

<p>in the public member of QSweep
with the call:</p>

<pre><code>int main(){
...
sort(myVector1.begin(),myVector1.end(),sortx);
}
</code></pre>

<p>but I keep having the same error (even if I modified something):
sort.cpp: In static member function 'static bool QSweep::sortx(const std::vector >&amp;, const std::vector >&amp;)':
sort.cpp:47: error: invalid use of member 'QSweep::myPoints_' in static member function
sort.cpp:25: error: from this location
sort.cpp:47: error: invalid use of member 'QSweep::myPoints_' in static member function
sort.cpp:25: error: from this location
sort.cpp: In function 'int main()':
sort.cpp:106: error: 'sortx' was not declared in this scope</p>

<p>Then I tried to write a functor for my class (which I never worked with before):
The functor is:</p>

<pre><code>class order{
public:
QSweep* o;
//vector&lt; vector&lt;double&gt; &gt; myPoints_;
bool operator() (const vector&lt;int&gt;&amp; edge1, const vector&lt;int&gt;&amp; edge2){
return o-&gt;myPoints_[edge1[0]][0]&lt;o-&gt;myPoints_[edge2[0]][0];
}
};
</code></pre>

<p>and I defined it outside the Class QSweep.
And I call the functor in the main program as:</p>

<pre><code>sort(myVector1.begin(),myVector1.end(),order());
</code></pre>

<p>The program compiles but I get an bus error message:
./sort
1 2
2 3
1 3
Bus error</p>

<p>oii so definitely my functor is not good..
should I initialize the object of class QSweep somehow. I do not understand how this functor will know to use exactly myPoints_ elements from QSweep class..</p>

<p>thank you in advance,
madalina</p>
