laserlight, CornedBee, thanks for the help. I think I'm almost there, but still getting an error. I can't find a way to fix it. Any ideas would be really welcome ! Thanks.
Comparison Class .h
Code:
// pathcompare.h
// Class PathCompare
#ifndef _PATHCOMPARE_H
#define _PATHCOMPARE_H
#include "paths.h"
#include "graph.h"
class PathCompare
{
public:
// Constructor
PathCompare(const Graph &);
// () Operator
bool operator() (Paths &, Paths &);
private:
// Graph variable
const Graph * graph;
};
#endif
Comparison Class .cpp
Code:
// pathcompare.cpp
// Class PathCompare
#include "pathcompare.h"
PathCompare::PathCompare(const Graph & mygraph)
{
graph = mygraph;
}
bool PathCompare::operator() (Path & left, Path & right)
{
return left.getLength(graph) < right.getLength(graph)
}
Snippet of main.cpp
Code:
// ...
// Get the direct paths from sources to sinks in graph Q
list <Paths> finallist = directpaths(Q);
// Create a PathCompare object, with graph argument
PathCompare comparefunction(Q);
// Create a priority queue storing Paths objects, in a vector container, using the PathCompare object above
priority_queue < Paths, vector <Paths>, comparefunction > pq;
// Fill the queue
for(list<Paths>::iterator i = finallist.begin(); i != finallist.end(); i++)
{
pq.push(*i);
}
// ...
This produces these errors on compile :
Code:
main.cpp: In function 'int main()':
main.cpp:136: error: comparefunction' cannot appear in a constant-expression
main.cpp:136: error: template argument 3 is invalid
main.cpp:136: error: invalid type in declaration before ';' token
main.cpp:141: error: request for member 'push' in 'pq', which is of non-class type 'int'
136 is the line which creates the priority_queue object.
Thank you very much for any help !