0

我有一个图表类:

#ifndef GRAPH_H
#define GRAPH_H

#include<list>
#include<iostream>
#include "global.h"

class Graph_{

std::list<Vertex> vertices;
int vcount;
int ecount;

public:
    void insert_vertex(Vertex vert);
    int routesearch(Graph_ *passed, Vertex *vert,  double distance, double curdistance, double safety, double minsafe, int startID);



};


#endif

然后在我的主要部分中,我尝试访问我声明的图中的顶点列表,它给了我一个错误:8 IntelliSense:成员“Graph_::vertices”不可访问。不知道该怎么做,因为它适用于我制作的所有其他结构,例如 Vertex,除了我制作的类。

 #include "graph.h"
 int main(){
    Vertex dumb;
    Graph_ map;
    map.vertices.push_back(dumb);

}

4

1 回答 1

2

它适用于我制作的所有其他结构

struct具有public默认访问级别。class才不是。public如果您想访问它,请创建该成员:

class Graph_{
//these two are private, because a class has private access level by default
    int vcount;
    int ecount;
public: // <<<--- public here
    std::list<Vertex> vertices;
public:
    void insert_vertex(Vertex vert);
    int routesearch(Graph_ *passed, Vertex *vert,  double distance, double curdistance, double safety, double minsafe, int startID);



};
于 2012-12-06T02:04:35.333 回答