[英]enum is not a non-static data member or base class of class
Hey i am trying to write BFS algorithm.My graph class looks like this. 嘿,我正在尝试编写BFS算法。我的图类看起来像这样。
class Graph {
struct Vertice{
int ID;
int distance;
enum color{ WHITE, GREY, BLACK };
Vertice* parent;
Vertice(int n) :ID(n), distance(0), color(WHITE), parent(0){};
};
public:
Graph(int n) : adjList(n) {
}
void add_edge(int u, int v) {
adjList[u - 1].insert(adjList[u].begin(),Vertice(v));
adjList[v - 1].insert(adjList[v - 1].begin(), Vertice(u));
}
vector<int> shortest_reach(int start) {
}
vector<list<Vertice>> adjList;
};
In the initializer list of the constructor for struct Vertice i get the following error color is not a non-static data member or base class of class Graph::Vertice. 在struct Vertice的构造函数的初始化程序列表中,我得到以下错误颜色不是Graph :: Vertice类的非静态数据成员或基类。 I googled as much as i could but did not find anything similar to this.
我尽可能地用Google搜索,但没有找到与此类似的内容。
enum color{ WHITE, GREY, BLACK };
This will only define the values, not as one of them being instansiated inside each Vertice
. 这将仅定义值,而不是在每个
Vertice
内部Vertice
其中的一个。
Add another line to also use a value: 添加另一行以也使用一个值:
enum class Color{ WHITE, GREY, BLACK };
Color color;
Vertice* parent;
Vertice(int n) :ID(n), distance(0), color(Color::WHITE), parent(0){};
In the above code snippet you are declaring the type, not a member of the Vertice
. 在上面的代码片段中,您声明了类型,而不是
Vertice
的成员。 See the code snippet below. 请参见下面的代码段。
class Graph {
typedef enum color_t{ WHITE, GREY, BLACK } color_t; // Declare the enum type here.
struct Vertice{
int ID;
int distance;
color_t color; // the member.
Vertice* parent;
Vertice(int n) :ID(n), distance(0), color(WHITE), parent(0){};
};
public:
Graph(int n) : adjList(n) {
}
void add_edge(int u, int v) {
adjList[u - 1].insert(adjList[u].begin(),Vertice(v));
adjList[v - 1].insert(adjList[v - 1].begin(), Vertice(u));
}
vector<int> shortest_reach(int start) {
}
vector<list<Vertice>> adjList;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.