Segmentation fault on instationation of more than 1 object
- by ECE
I have a class called "Vertex.hpp" which is as follows:
#include <iostream>
#include "Edge.hpp"
#include <vector>
using namespace std;
/** A class, instances of which are nodes in an HCTree.
*/
class Vertex {
public:
Vertex(char * str){
*name=*str;
}
vector<Vertex*> adjecency_list;
vector<Edge*> edge_weights;
char *name;
};
#endif
When I instantiate an object of type Vector as follows:
Vertex *first_read;
Vertex *second_read;
in.getline(input,256);
str=strtok(input," ");
first_read->name=str;
str=strtok(NULL, " ");
second_read->name=str;
A segmentation fault occurs when more than 1 object of type Vector is instantiated. Why would this occur if more than 1 object is instantiated, and how can i allow multiple objects to be instantiated?