0

I am trying to initialize a graph in boost. But I am getting an error I'm not able to understand.

typedef typename boost::adjacency_list
    <
    boost::vecS,
    boost::vecS,
    boost::directedS,
    boost::no_property,
    boost::property< boost::edge_weight_t, unsigned int >
    > Graph;

Graph g;
std::ifstream fileIn(FILENAME);
if (fileIn.is_open()) {
    std::vector<Edge> edgeVector;
    std::vector<unsigned int> edgeWeightVector;
    while (!fileIn.eof()) {
        std::string line;
        unsigned int sourceNode, destinationNode, edgeWeight;
        std::getline(fileIn, line);
        std::istringstream iss(line);
        iss >> sourceNode;
        while (iss >> destinationNode >> edgeWeight) {
            edgeVector.push_back(Edge(sourceNode, destinationNode));
            edgeWeightVector.push_back(edgeWeight);
        }
        std::cout << std::endl;
    }
    g = Graph(edgeVector.begin(), edgeVector.end(), edgeWeightVector, VERTEXNUMBER);
}
else {
    std::cout << "Couldn't open file";
    return 1;
}

The error I am getting is illegal indirection and unary '++': 'EdgePropertyIterator' does not define this operator or a conversion to a type acceptable to the predefined operator at Graph initialization line g = Graph(edgeVector.begin(), edgeVector.end(), edgeWeightVector, VERTEXNUMBER);

If I click on that error, it takes me to boost implementation at following lines

add_edge((*first).first, (*first).second, *ep_iter, static_cast<Graph&>(*this));
          ++first;
          ++ep_iter;
genpfault
  • 51,148
  • 11
  • 85
  • 139
rafee
  • 1,731
  • 18
  • 21
  • What is the Graph type? Can you add its typedef definition? – TonySalimi Jul 29 '19 at 15:55
  • 1
    `Graph(edgeVector.begin(), edgeVector.end(), edgeWeightVector.begin(), VERTEXNUMBER);` ? – rafix07 Jul 29 '19 at 16:24
  • @rafix07 no he is looking for something different. – rafee Jul 29 '19 at 17:36
  • @Hoodi added typedef – rafee Jul 29 '19 at 17:38
  • 2
    @rafee My previous comment is the solution to your problem. According to [reference](https://www.boost.org/doc/libs/1_37_0/libs/graph/doc/adjacency_list.html) you try to call `adjacency_list` constructor with iterator as third parameter. The error message is clear, `++` is called on vector - `EdgePropertyIterator`, and it doesn't work. But `++` can be easily called on `iterator`. – rafix07 Jul 29 '19 at 17:43
  • 1
    @rafix07 Sorry for the misunderstanding. It's working now. Can you write an answer with details that I can accept? – rafee Jul 29 '19 at 17:50

0 Answers0