枚举尚未声明
Enum has not been declared
我使用以下标头Node.h
:
/*
INCLUDE PROTECTION
*/
#ifndef NODE_H_INCLUDED
#define NODE_H_INCLUDED
/*
Include
*/
#include <vector>
#include <unordered_map>
//#include "NodeConnection.h"
#include "Tile.h"
#include "Network.h"
/*
Declarations
*/
class Network;
class NodeConnection;
class Node {
private:
Tile* tile;
std :: vector <NodeConnection*> connections;
std :: unordered_map <Node*, NodeConnection*> connectionmap;
public:
/* Enumeration */
enum NAVIGATION {
RIGHT = 0,
UP = 1,
LEFT = 2,
DOWN = 3
};
Node (Tile* _tile);
void FindNeighbours(Board* board, Network* network);
void SetNodeConnection(Node* node, NodeConnection* nodeconnection);
};
struct TileNavigation {
Tile* tile;
enum Node :: NAVIGATION navigation;
};
#endif
在NodeConnection.h
的标题中以下内容:
/*
INCLUDE PROTECTION
*/
#ifndef NODECONNECTION_H_INCLUDED
#define NODECONNECTION_H_INCLUDED
/*
Include
*/
#include <string>
#include "Node.h"
/*
Declarations
*/
class Node;
struct Nodes;
enum ConnectionType {
WALLCONN, PATHCONN, UNKNOWN
};
class NodeConnection {
private:
enum ConnectionType contype;
struct Nodes;
public:
//NodeConnection ();
NodeConnection (Node* a, Node* b, NAVIGATION initial_nav);
};
struct Nodes {
Node* left;
Node* right;
std :: string steps;
};
#endif
我已经尝试过Node :: NAVIGATION
和NAVIGATION
,但它一直告诉我
" 'NAVIGATION' has not been declared "
有谁知道我做错了什么?提前感谢您的指点。
你有circuit-include
问题。 Node.h
和NodeConnection.h
相互包容。
要修复:
在Node.h
中向前声明Nodeconnection
,从 Node.h 中删除#include "NodeConnection.h"
以解决circuit-including
问题。
//#include "NodeConnection.h" //
class Network;
class NetworkConnection; // forward declare NetworkConnection
class Node {
//..
};
在 Node.cpp 文件中包含NodeConnection.h
。
#include "NodeConnection.h"
在 NodeConnection.h 中使用Node::NAVIGATION
class NodeConnection {
private:
//enum ConnectionType contype; don't need to use enum keyword again.
ConnectionType contype;
public:
//NodeConnection ();
NodeConnection (Node* a, Node* b, Node::NAVIGATION initial_nav);
};
相关文章:
- 访问在 C++ 结构中声明的枚举变量
- 如何转发声明枚举?
- C++:如何在声明枚举类的模板类主体之外定义枚举类?
- 在C++代码中使用的 C 标头中向前声明枚举
- 在哪里声明枚举
- 在模板参数内向前声明枚举类
- 在C++14中,在哪个作用域中声明了重新声明枚举的非范围枚举器
- 在C中定义的C++中正向声明枚举
- 在不膨胀命名空间的情况下在C++中声明枚举的好方法
- 声明枚举标识符的基础类型
- 为什么在向前声明枚举时必须提供枚举的大小?
- 枚举包含在标头中 |未声明错误
- 错误:枚举未在此范围内声明
- 前向声明枚举类不起作用
- 在运行时有条件地声明枚举(C++)
- 我可以传递前向声明枚举的值吗?
- c++ -对声明枚举感到困惑
- c++:在类内部从外部声明枚举器,以便可以在私有成员中使用
- 在声明枚举之前使用它
- 当试图添加类构造时,C++未设置枚举类型