Enum尚未宣布

时间:2013-10-11 22:17:32

标签: c++ enums

我使用以下标题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 :: NAVIGATIONNAVIGATION,但它一直告诉我

"   'NAVIGATION' has not been declared   "

有谁知道我做错了什么?提前感谢指点。

1 个答案:

答案 0 :(得分:2)

您有circuit-include个问题。 Node.hNodeConnection.h互相包含。

修复:

Nodeconnection中转发声明Node.h,从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);

};