简体   繁体   English

Enum尚未宣布

[英]Enum has not been declared

I use the following header Node.h : 我使用以下头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

And the following in the header of NodeConnection.h : 以下是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

I have tried Node :: NAVIGATION and NAVIGATION , but yet it keeps telling me that 我尝试过Node :: NAVIGATIONNAVIGATION ,但它一直告诉我

"   'NAVIGATION' has not been declared   "

Does anyone know what I am doing wrong? 有谁知道我做错了什么? Thanks in advance for pointers. 提前感谢指针。

Your have circuit-include issue. 你有circuit-include问题。 Node.h and NodeConnection.h include each other. Node.hNodeConnection.h包含。

To fix: 修理:

Forward declare Nodeconnection in Node.h , remove #include "NodeConnection.h" from Node.h to break circuit-including issue. Node.h转发声明Nodeconnection ,从Node.h中删除#include "NodeConnection.h"以打破circuit-including问题。

//#include "NodeConnection.h"  // 
class Network;
class NetworkConnection; // forward declare NetworkConnection
class Node {
//..
};

include NodeConnection.h in Node.cpp file. 在Node.cpp文件中包含NodeConnection.h

#include "NodeConnection.h"

use Node::NAVIGATION in 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);

}; };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM