0

I use the following header 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:

/*
    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

"   'NAVIGATION' has not been declared   "

Does anyone know what I am doing wrong? Thanks in advance for pointers.

9
  • 2
    Node::NAVIGATION should work... Commented Oct 11, 2013 at 22:20
  • 1
    Can you provide an SSCCE there is some detail missing in your sample code, using Node::NAVIGATION should work see live example. Commented Oct 11, 2013 at 22:22
  • NodeConnection (Node* a, Node* b, Node :: NAVIGATION initial_nav); does not work, it gives the same error Commented Oct 11, 2013 at 22:22
  • Yes, so can you provide an SSCCE? There is no way to tell what the problem is from the code given. Commented Oct 11, 2013 at 22:23
  • 2
    Node::NAVIGATION works as is, so you're not telling us some important detail. for example, is Node declared within a namespace? Commented Oct 11, 2013 at 22:23

1 Answer 1

4

Your have circuit-include issue. Node.h and NodeConnection.h include each other.

To fix:

Forward declare Nodeconnection in Node.h, remove #include "NodeConnection.h" from Node.h to break circuit-including issue.

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

include NodeConnection.h in Node.cpp file.

#include "NodeConnection.h"

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

};

Sign up to request clarification or add additional context in comments.

3 Comments

It has not fixed the issue :S Thanks for the advice though
Thanks, that does work. But now it indicates an error in invalid use of incomplete type 'class NodeConnection' ><
#include "NodeConnection.h" in Node.cpp file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.