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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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.

Thank you all in advance for your time and effort!
You have an extra < before 'vector' on line 7
Topic archived. No new replies allowed.