Segmentation fault on instationation of more than 1 object

Posted by ECE on Stack Overflow See other posts from Stack Overflow or by ECE
Published on 2012-12-04T22:54:31Z Indexed on 2012/12/04 23:03 UTC
Read the original article Hit count: 168

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about oop