# Define custom comparison

• 11-15-2009
Lagrange
Define custom comparison
Hello fellow programmers.

This question should be easy, but already wasted hours of googling and testing I now turn to you. As a part of a project I am using a vector < vector <double > > data structure and want to sort the "outer" vector by comparing the "inner" vectors. For my case this makes sense and should be done simply by comparing the first two numbers (doubles).

I am getting a "error C4430: missing type specifier - int assumed" error amongst others when trying to compile. I have tested and identified the following part of the code as the problem. Also a syntax error missing ")" before "<" on my custom comparison.

Code:

```#include <vector> #include <iostream> #include <algorithm> using namespace std; //First define the sorting - getting the bool SortOnFirstElement(const < vector<double> &u,const vector<double> &v)         {             if(u[0]< v[0]) return true;             else return false;         } int main() { //lot of other code that was written and tested before the custom comparison //came into play     vector < vector<double> > ratio;     vector < vector<double> >* pratio =&ratio; //Then some initialization of the ratio vector. I have checked it is //intitalized correctly by printing out     //Now sort     sort((*pratio).begin(),(*pratio).end(), SortOnFirstElement); }```
I know I probably should use -> instead of the (*). If more code is needed please ask. The problem is almost certaintly in the part defining the comparison. For the interested I can say the method will eventually solve instances of the multiple-choice knapsack problem.

• 11-15-2009
laserlight
At a glance, it looks like a typo error here:
Code:

`bool SortOnFirstElement(const < vector<double> &u,const vector<double> &v)`
i.e., it should be:
Code:

`bool SortOnFirstElement(const vector<double> &u, const vector<double> &v)`
Out of curiosity, but why do you need pratio when ration appears to be in the same scope?
• 11-15-2009
Lagrange
Doh!

The code is now compilling. I guess there is no reason I use pointers for the vector, hence I should probably not use it. Thanks for that point!