I'm trying to sort the values of a vector of positions (V) based on the comparison of the values of a vector of weights (A). I created a vector of struct to link the two vectors as I saw in some forums, however, my program does not compile and I don't understand why. Here's my code :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <sstream>
#include <stdbool.h>
#include <time.h>
#include <math.h>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <list>
#include <numeric>
#include <random>
#include <vector>
int main(int argc, char **argv)
{
struct WeightsAndPositions {
std::vector<float> weights;
std::vector<int> positions;
bool operator() (WeightsAndPositions &i,WeightsAndPositions &j) { return (i.weights<j.weights);}
} weights_and_positions;
std::vector<WeightsAndPositions> WandP;
WeightsAndPositions tmp_WandP;
std::vector <float> A;
A.push_back(12);
A.push_back(4);
A.push_back(33);
A.push_back(10);
A.push_back(0);
A.push_back(5);
std::vector <int> V;
V.push_back(0);
V.push_back(1);
V.push_back(2);
V.push_back(13);
V.push_back(41);
V.push_back(5);
tmp_WandP.weights=A;
tmp_WandP.positions=V;
WandP.push_back(tmp_WandP);
sort(WandP.begin(), WandP.end(),tmp_WandP);
return EXIT_SUCCESS;
}
Here's the error I get after compilation:
erreur: no match for call to ‘(main(int, char**)::WeightsAndPositions) (main(int, char**)::WeightsAndPositions&, const main(int, char**)::WeightsAndPositions&)’
and I don't understand why I have this error and how to fix it.
I would be grateful for any help,
Thanks.