令牌前的预期表达式
Expected expression before token
这是我得到的代码,在尝试编译它时,我遇到了两个错误,不幸的是我目前没有发现,希望另一双眼睛能指出一些见解。
错误落在这两行
print_all_paths(graph, int source_id, int destination_id, visited_arr, path, path_counter);
这个错误是:
error: expected expression before 'int'
第二个错误发生在:
void print_all_paths(Graph* graph, int source_id, int destination_id, int visited_arr[], int path[], int &path_counter)
显示:
error: expected ';', ',' or ')' before '&' token
谢谢!
我想你想要一个 * 而不是 &
当你声明一个函数时,你应该提供传递给函数的参数的所有数据类型。但是,当你调用函数时,你不需要指定传递值的数据类型,因为它们已经在函数头中定义了。
因此将导致第一个错误的行更改为:
print_all_paths(graph, source_id, destination_id, visited_arr, path, path_counter); // The "int" is removed
第二个错误是因为在C中不能引用变量;那是 C++ 特性。因此,您应该在函数 void print_all_paths
中更改 int *path_counter
而不是 int &path_counter
这是我得到的代码,在尝试编译它时,我遇到了两个错误,不幸的是我目前没有发现,希望另一双眼睛能指出一些见解。
错误落在这两行
print_all_paths(graph, int source_id, int destination_id, visited_arr, path, path_counter);
这个错误是:
error: expected expression before 'int'
第二个错误发生在:
void print_all_paths(Graph* graph, int source_id, int destination_id, int visited_arr[], int path[], int &path_counter)
显示:
error: expected ';', ',' or ')' before '&' token
谢谢!
我想你想要一个 * 而不是 &
当你声明一个函数时,你应该提供传递给函数的参数的所有数据类型。但是,当你调用函数时,你不需要指定传递值的数据类型,因为它们已经在函数头中定义了。
因此将导致第一个错误的行更改为:
print_all_paths(graph, source_id, destination_id, visited_arr, path, path_counter); // The "int" is removed
第二个错误是因为在C中不能引用变量;那是 C++ 特性。因此,您应该在函数 void print_all_paths
int *path_counter
而不是 int &path_counter