struct Edge;
struct Node {
int id;
vector<Edge> *edges;
};
struct Edge {
int id;
Node* vertex1;
Node* vertex2;
};
int main(){
vector<Edge> nodeEdgeList;
Node* nodePtr = new Node;
nodePtr->id = vertex;
nodePtr->edges = nodeEdgeList;
}
I get the following compiler error due to the last line.
error: cannot convert 'std::vector<Edge, std::allocator<Edge> >' to 'std::vector<Edge, std::allocator<Edge> >*' in assignment
You Node class has a vector * as a member you are trying to set a non pointer to a pointer
The error message is pretty clear here error: cannot convert 'std::vector<Edge, std::allocator<Edge> >' to 'std::vector<Edge, std::allocator<Edge> >*' in assignment
so change to:
int main(){
vector<Edge> *nodeEdgeList = new Vector<Edge>;
Node* nodePtr = new Node;
nodePtr->id = vertex;
nodePtr->edges = nodeEdgeList;
}
or
int main(){
vector<Edge> nodeEdgeList;
Node* nodePtr = new Node;
nodePtr->id = vertex;
nodePtr->edges = &nodeEdgeList;
}
int main(){
vector<Edge> nodeEdgeList;
Node* nodePtr = new Node;
nodePtr->id = vertex;
nodePtr->edges = &nodeEdgeList; // <-- use & before
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.