B
Bob
Hi All,
I defined the following class:
class Graph {
public:
Graph() { }
int genRandGeomGraph(int i_nodes, double i_radius);
void print();
~Graph() {
if( NodeList ) delete [] NodeList;
}
private:
class Node {
public:
Node() {}
Node(int inID) { this->ID = inID; }
inline int getID() {return this->ID;}
inline void setID(int newID) { this->ID = newID; }
inline void setx(double inx) { this->x = inx; }
inline double getx() { return this->x; }
inline void sety(double iny) { this->y = iny; }
inline double gety() { return this->y; }
~Node() { if ( neighbors ) delete [] neighbors; }
private:
double x, y;
int ID;
std::vector<int>* neighbors;
};
std::vector<Node>* NodeList;
};
whenever I try to access NodeList from genRandGeomGraph(...)
int Graph::genRandGeomGraph((int i_nodes, double i_radius) {
NodeList = new vector< Node >(nnodes);
std::cout << NodeList->size();
return 1;
}
I get segmentation fault. Shouldn't I be able to access it?
Thanks
I defined the following class:
class Graph {
public:
Graph() { }
int genRandGeomGraph(int i_nodes, double i_radius);
void print();
~Graph() {
if( NodeList ) delete [] NodeList;
}
private:
class Node {
public:
Node() {}
Node(int inID) { this->ID = inID; }
inline int getID() {return this->ID;}
inline void setID(int newID) { this->ID = newID; }
inline void setx(double inx) { this->x = inx; }
inline double getx() { return this->x; }
inline void sety(double iny) { this->y = iny; }
inline double gety() { return this->y; }
~Node() { if ( neighbors ) delete [] neighbors; }
private:
double x, y;
int ID;
std::vector<int>* neighbors;
};
std::vector<Node>* NodeList;
};
whenever I try to access NodeList from genRandGeomGraph(...)
int Graph::genRandGeomGraph((int i_nodes, double i_radius) {
NodeList = new vector< Node >(nnodes);
std::cout << NodeList->size();
return 1;
}
I get segmentation fault. Shouldn't I be able to access it?
Thanks