title: Sorting a vector inside a custom class C++ using std::sort
body: <p>How do I sort two vectors inside a custom class using std::sort?</p>
  
  <p>As an example, let's say I have a class containing two vectors, ids and marks. After initializing the vectors, I would like to sort the elements of this class by marks, preserving the sorted order in the ids.</p>
  
  <p>I've attempted to do this using the custom <code>std::sort</code> function. </p>
  
  <pre><code>class Example
  {
  public:
      void init();
      static bool sortByMarks(const Example &amp;lhs, const Example &amp;rhs);
      //....other functions
  
  private:
      vector&lt;int&gt; ids;
      vector&lt;int&gt; marks;
      //....other variables   
  }
  void Partition::init()
  {
      ids.resize(5);
      marks.resize(5);
      for(int i=0;i&lt;5;i++)
           ids[i]=i+1;
      marks[0]=47;marks[1]=44;marks[2]=88;marks[3]=52;marks[4]=46;
  }
  bool Partition::sortByMarks(const Example &amp;lhs, const Example &amp;rhs);
  {
      return lhs.marks &lt; rhs.marks;
  }
  </code></pre>
  
  <p>EDIT: [This is fixed by adding the Example:: to the function call] I'm having trouble calling this function. I tried the following:</p>
  
  <pre><code>Example e; 
  sort(&amp;e, &amp;e, Example::sortByMarks);
  </code></pre>
  
  <p>Sample Input:</p>
  
  <p><code>ids  : 1,2,3,4,5
  marks: 47,44,88,52,46</code></p>
  
  <p>Sample Output:</p>
  
  <p><code>ids  : 2,5,1,4,3 
  marks: 44,46,47,52,88</code></p>
  
  <p>Any help is appreciated!</p>
  
  <p>EDIT: Marks vector is what I want sorted (ids should also be changed accordingly)</p>