Could anyone help me resolve the circular reference errors I'm getting here.
I've created my own deque
class which is used by the breadthFirst
method of FibTree
.
Below are the highlights from the separate Header and CPP files. There are issues with invalid use of incomplete type and forward declaration error in FibTree
files. I've marked these errors on the lines of code below.
deque.h
#ifndef DEQUE_H
#define DEQUE_H
#include "fibtree.h"
class dequeNode {
public:
FibTree::Node* data;
};
class dequeList {
public:
dequeNode* firstNode;
dequeNode* lastNode;
dequeList( void );
void enque( FibTree::Node* );
FibTree::Node* deque( void );
};
#endif
fibtree.h
#ifndef FIBTREE_H
#define FIBTREE_H
#include <iostream>
class dequeList; // ERROR: Forward declaration of 'struct dequeList' (2 ERRORS)
class FibTree {
public:
class Node {
...
};
Node const* root; // 'root' pointer to constant Node
FibTree (int);
void breadthFirst(Node const* root);
};
#endif
fibtree.cpp
#include "fibtree.h"
void FibTree::breadthFirst(Node const* root) { // Breadth-first traversal
dequeList* list = new dequeList(); //*** ERROR: Invalid use of incomplete type 'struct dequeList'
list->enque(root); //*** ERROR: Invalid use of incomplete type 'struct dequeList'
}
main.cpp
#include <iostream>
#include "deque.h"
#include "fibtree.h"
int main (int argc, const char* argv[]) {
...
I'd read on a similar post HERE, that the complete declaration should be included, in my case of dequeList
, so I added #include "deque.h"
above the forward declaration class deque.h"
, in fibtree.h; but this threw 16 compile errors to the deque.h
class, such as these three errors: 'FibTree' has not been declared against FibTree::Node* data; in
class dequeNode {...`
Would anyone be able to highlight where I may be going wrong here?
Thanks, Alex