2013-10-11 136 views
0

我用下面的頭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 " 

有沒有人知道wha我做錯了嗎?預先感謝指針。

+2

Node :: NAVIGATION應該工作... –

+1

你可以提供一個[SSCCE](http://sscce.org/)你的示例代碼中有一些細節丟失,使用'Node :: NAVIGATION' [should work看現場實例](http://coliru.stacked-crooked.com/a/38b1ce66e5f99f30)。 –

+0

'NodeConnection(Node * a,Node * b,Node :: NAVIGATION initial_nav);'不起作用,它給出相同的錯誤 – bas

回答

2

您有circuit-include問題。 Node.hNodeConnection.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" 

使用Node::NAVIGATION在NodeConnection.h

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); 

};

+0

它沒有解決的問題:S感謝您的建議,但 – bas

+1

應該使用'Node :: NAVIGATION',它應該工作 – billz

+0

謝謝,這是行不通的。但現在它指示在Node.cpp文件中使用不完整類型'class NodeConnection'>< – bas