0

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.

mja
  • 13
  • 5
  • why isn't the 3rd argument to sort `tmp_WandP`? – UKMonkey Feb 28 '18 at 10:43
  • @UKMonkey I updated line to: `sort(WandP.begin(), WandP.end(), tmp_WandP);` and I still have the same error – mja Feb 28 '18 at 10:50
  • we can't really help you unless you post the code that's causing you problems. It looks like you've truncated the code that you don't think is related; but you've definitely removed some that is. – UKMonkey Feb 28 '18 at 10:53
  • *I'm trying to sort the values of a vector of positions* Your code does not reflect that. – O'Neil Feb 28 '18 at 10:54
  • @UKMonkey I have just posted my whole code – mja Feb 28 '18 at 11:15
  • @O'Neil Could you please explain why you say that because I have been struggling with this issue for days now. Thanks in advance – mja Feb 28 '18 at 11:15
  • `WandP` and `tmp_WandP.positions` are two different vertors. Your code is trying to sort `WandP` (which contains a single element in the code you show: `tmp_WandP`). – O'Neil Feb 28 '18 at 11:48

0 Answers0