我在新对象的实例中遇到各种错误。这是我第一次用 c++ 编程,所以我什么都不知道,但我真的不知道我想念什么。以下是我的代码和相关错误的一些示例。
Edge newEdge;
newEdge = new Edge(vertex2, neighbors(vertex1)); // create a new edge without weight
出现的错误是:
invalid conversion from `Edge*' to `int'
initializing argument 1 of `Edge::Edge(int, Edge*, unsigned int)'
并且构造函数是
public: Edge(int nextVertex = 0, Edge* ptr = NULL, unsigned int weight = 1):nextVertex(nextVertex),
next(ptr),
weight(weight){};
其他类也类似:
PriorityQueue queue = new PriorityQueue();
错误:
conversion from `PriorityQueue*' to non-scalar type `PriorityQueue' requested
代码:
VertexPriority aux;
错误:
no matching function for call to `VertexPriority::VertexPriority()'
最后
ShortestPath shortp = new ShortestPath(graph);
错误:
conversion from `ShortestPath*' to non-scalar type `ShortestPath' requested
还有一个错误,我认为我限制了之前的错误,因为它是一个实例并且错误相似,这里是代码:
queue.insert(new VertexPriority(vertex1, 0));
错误是:
no matching function for call to `PriorityQueue::insert(VertexPriority*)'
candidates are: void PriorityQueue::insert(VertexPriority)
对象的构造函数是
VertexPriority(int vertex, unsigned int priority):vertex(vertex),
priority(priority){};
并且方法 insert 需要一个顶点作为参数:void insert(VertexPriority vertex);
我在我的代码中错过了什么?