我有一个名为“Vertex.hpp”的类,如下所示:
#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
当我按如下方式实例化 Vector 类型的对象时:
Vertex *first_read;
Vertex *second_read;
in.getline(input,256);
str=strtok(input," ");
first_read->name=str;
str=strtok(NULL, " ");
second_read->name=str;
当实例化超过 1 个 Vector 类型的对象时,会发生分段错误。如果实例化超过 1 个对象,为什么会发生这种情况,如何允许实例化多个对象?