add_edge导致"no function to call error"

add_edge causing "no function to call error"

本文关键字:to call error function no edge 导致 add      更新时间:2023-10-16

我在我的add_edge函数上获得了"无函数要调用"。Boost肯定是正确包含的,因此我认为这不是问题。这是称为

的功能
void initializeGraph(Graph &g,
                  Graph::vertex_descriptor &start,
                 Graph::vertex_descriptor &end, ifstream &fin)
// Initialize g using data from fin.  Set start and end equal
// to the start and end nodes.
{
edgeProperties e;
int n, i, j;
int startId, endId;
fin >> n;
fin >> startId >> endId;
Graph::vertex_descriptor v;
// Add nodes.
for (int i = 0; i < n; i++)
{
    v = add_vertex(g);
    if (i == startId)
        start = v;
    if (i == endId)
        end = v;
}
while (fin.peek() != '.')
{
    fin >> i >> j >> e.weight;
    add_edge(i,j,e,g);
}
}

这就是我称之为函数的方式:

Graph g;
Graph::vertex_descriptor start, end, curr;
initializeGraph(g, start, end, infile);

关于为什么发生这种情况的任何想法都会很棒,因为我真的迷路了!

您无法提供一个独立的示例。从我看到的东西中拼凑出最低限度,没有问题:

活在coliru

#include <boost/graph/adjacency_list.hpp>
#include <fstream>
struct edgeProperties {
    double weight;
};
using Graph = boost::adjacency_list<boost::vecS, boost::vecS,boost::directedS, boost::no_property, edgeProperties>;
void initializeGraph(Graph &g, Graph::vertex_descriptor &start, Graph::vertex_descriptor &end, std::ifstream &fin)
// Initialize g using data from fin.  Set start and end equal to the start and end nodes.
{
    edgeProperties e;
    int n, i, j;
    int startId, endId;
    fin >> n;
    fin >> startId >> endId;
    Graph::vertex_descriptor v;
    // Add nodes.
    for (int i = 0; i < n; i++) {
        v = add_vertex(g);
        if (i == startId)
            start = v;
        if (i == endId)
            end = v;
    }
    while (fin.peek() != '.' && fin >> i >> j >> e.weight) {
        add_edge(i, j, e, g);
    }
}
#include <boost/graph/graph_utility.hpp>
int main() {
    std::ifstream infile("input.txt");
    Graph g;
    Graph::vertex_descriptor start, end/*, curr*/;
    initializeGraph(g, start, end, infile);
    print_graph(g);
}

for Input.txt:

5
0 4
2 3 1
1 2 1
3 4 1
0 2 1
.

打印:

0 --> 2 
1 --> 2 
2 --> 3 
3 --> 4 
4 -->