A
affernan
Guest
It turns out that I have the well-known error "C2064 term does not evaluate to a function taking 2 arguments". I have looked at various posts and they recommend the following: Declare the comparison function as 'static', 'virtual', make a regular function and not a method, but those options seem logical but they have not worked for me. I explain my code and a possible reason for my error:
Code:
//Grasp.h
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <random>
#include <ctime>
using namespace std;
struct NODE {
int NodeNumber;
string CityName;
int Demand;
int ReadyTime;
int DueTime;
int ServiceTime;
};
class Grasp {
public:
Grasp ();
~Grasp ();
bool clientes_sorter_distancia(const NODE&, const NODE&);
void CONSTRUCTIVE();
private:
vector<NODE > Cities;
vector<vector<int> > Distance;
NODE Depot;
NODE actual;
};
//Grasp.cpp
#include "Grasp.h"
Grasp::Grasp()
{}
Grasp::~Grasp()
{}
bool Grasp::clientes_sorter_distancia(const NODE& lhs, const NODE& rhs)
{
vector<int> dist = Distance[actual.NodeNumber];
return dist[lhs.NodeNumber] < dist[rhs.NodeNumber];
}
void Grasp::CONSTRUCTIVE()
{
//...
actual = subtour.back();
sort(cities.begin(), cities.end(), &Grasp::clientes_sorter_distancia); //ordenar clientes por mas cercano a un nodo dado
//...
}
Possible reason:
In the implementation of the function (clients_sorter_distance) I make use of the "Distance" vector because I need it, but when trying the friend alternative, the error C2064 seems to disappear, but the method tells me that since it no longer belongs to the 'Grasp' class and therefore cannot see the vector.
How can I fix error C2064 and be able to use the comparison function in the way that I have it implemented?
Regards.
Continue reading...
Code:
//Grasp.h
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <random>
#include <ctime>
using namespace std;
struct NODE {
int NodeNumber;
string CityName;
int Demand;
int ReadyTime;
int DueTime;
int ServiceTime;
};
class Grasp {
public:
Grasp ();
~Grasp ();
bool clientes_sorter_distancia(const NODE&, const NODE&);
void CONSTRUCTIVE();
private:
vector<NODE > Cities;
vector<vector<int> > Distance;
NODE Depot;
NODE actual;
};
//Grasp.cpp
#include "Grasp.h"
Grasp::Grasp()
{}
Grasp::~Grasp()
{}
bool Grasp::clientes_sorter_distancia(const NODE& lhs, const NODE& rhs)
{
vector<int> dist = Distance[actual.NodeNumber];
return dist[lhs.NodeNumber] < dist[rhs.NodeNumber];
}
void Grasp::CONSTRUCTIVE()
{
//...
actual = subtour.back();
sort(cities.begin(), cities.end(), &Grasp::clientes_sorter_distancia); //ordenar clientes por mas cercano a un nodo dado
//...
}
Possible reason:
In the implementation of the function (clients_sorter_distance) I make use of the "Distance" vector because I need it, but when trying the friend alternative, the error C2064 seems to disappear, but the method tells me that since it no longer belongs to the 'Grasp' class and therefore cannot see the vector.
How can I fix error C2064 and be able to use the comparison function in the way that I have it implemented?
Regards.
Continue reading...