0
來自這個問題this one
一個統一體我有一個列表的向量在我的節點類沒有被傳遞給其他的功能。傳遞載體容器等功能
這裏是Node.h
#include "MyGraph.h"
//The Node Class will take the information from the graph class and
//convert the information into a format so we can perform DFS on our
//graph.
enum VertexState { White, Gray, Black };
class Node {
private:
string nodeId;
VertexState status; //whether or not the vertex Node has been visited or not
vector<Node> nodeList;
vector<list<Node> > *edgeList;
public:
Node(): nodeId(), status(){}
//copy constructor
Node(string vertex){
nodeId=vertex;
status = White;
}
~Node(){}
//Setter and Getter methods for our class variables
void setId(string vertex){
nodeId = vertex;
}
void setStatus(VertexState newStatus){
status = newStatus;
}
string getNodeId(){
return nodeId;
}
VertexState getStatus(){
//status == White then it is not visited
//status == Gray its being processed
//status == Black then it has been visited
return status;
}
vector<Node> getNodeList(){
return nodeList;
}
vector<list<Node> > getEdgeList(){
return *edgeList;
}
//create nodes from vertex list in the graph object
void createNodeList(MyGraph graphObject){
vector<string> vertexList;
vertexList = graphObject.getVertexList();
vector<string>::iterator it;
vector<Node>placeNodeList;
for (it = vertexList.begin(); it !=vertexList.end(); it++){
Node newNode(*it);
placeNodeList.push_back(newNode);
}
nodeList = placeNodeList;
cout << "Size of initial nodeList: " << nodeList.size()<<endl;
}
//creates container for edge lists from the graph object
void createEdgeList(MyGraph graphObject){
vector<list<string> > newEdgeList;
newEdgeList = graphObject.getEdgeList();
vector<list<Node> > myEdgeList;
vector<list<string> >::iterator it;
for (it = newEdgeList.begin() ; it != newEdgeList.end(); it++) {
list<string> edgeString;
list<string>::iterator eIt;
edgeString =*it;
list<Node> edgeContainer; //creates a list container to be pushed on to our edgeList variable
for (eIt = edgeString.begin(); eIt != edgeString.end(); eIt++) {
Node newNode(*eIt);
edgeContainer.push_back(newNode);
}
myEdgeList.push_back(edgeContainer);
}
edgeList = &myEdgeList;
cout << "Size of intial edgeList: "<<edgeList->size() <<endl;
}
//The operational methods that will work on the Nodes of the graph
vector<Node> dephtFirstSearch(Node vertex);//will determine if our graph is connected.
vector<Node> DFS2(vector<Node> copyNodeList);
bool isGraphConnected(vector<Node> nodeList);
bool isEdgeConnected(Node vertex1, Node vertex2);//will determine if there is an edge between two nodes
bool findElementaryCycles();
void findArticulationPoints();
void removeVertex(Node myNode, vector<Node>copyNodeList, vector<list<Node> >copyEdgeList);
};
當我嘗試使用調用矢量EdgeList都在我的其他功能: edgeList->空; 該函數不應該是空的。 createEdgeList函數每次需要使用時都會調用,所以它不是空的。 如何將數據從我的私有變量傳遞給函數?
http://stackoverflow.com/questions/13783090/sigbart-error-vectorlistmyclass沒有添加對不起鏈接 – danielBB
固定爲您 – Default
添加到它爲什麼o edgeList是一個裸指針? – KillianDS