【发布时间】:2021-01-19 05:06:26
【问题描述】:
Visual Studio Code 为 int size = graph->at(node)->size(); 行提供了“表达式必须具有指针类型”错误。我知道我可以使用references,但我想知道如何使用指针。
#include <vector>
using namespace std;
void getPathEdges(vector<vector<int>>* graph, int sink, int count, int node, vector<int>* path) {
if (node == sink) {
path->push_back(count);
}
else {
count++;
int size = graph->at(node)->size();
for (int i=0; i<size; i++) {
getPathEdges(graph, sink, count, i, path);
}
}
}
【问题讨论】:
-
您已经在问题中提到了它,但我只想回应您对参考资料的确认。原始指针很值得了解,但是一旦您开始编写任何大小的东西,您就会想从智能指针和引用的角度来考虑,只有在与旧库接口或没有其他选择时才考虑使用原始指针。
标签: c++ function pointers vector stdvector