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.
#include <vector>
#include <iostream>
#include <algorithm>
usingnamespace std;
//First define the sorting - getting the
bool SortOnFirstElement(const < vector<double> &u,const vector<double> &v)
{
if(u[0]< v[0]) returntrue;
elsereturnfalse;
}
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 =∶
//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!