Reputation: 636
I have 2 files that are both including the other file and I am getting strange errors.
#ifndef NODE_H
#define NODE_H
#include "model.h"
etc....
#endif
#ifndef MODEL_H
#define MODEL_H
#include "Node.h"
etc....
#endif
Here is my example code of what I am doing. Can somebody explain to me why this is not possible or allowed? And what I should do to get passed this problem.
Upvotes: 2
Views: 5994
Reputation: 141928
You have a circular dependency between Node
and model
.
To deal with this, instead of...
#include "Node.h"
...in model.h , forward declare...
class Node;
...and this will allow you to have Node& node;
in your Model
class
.
Or vice-versa.
Better still... see if you can revisit your design and eliminate this circular dependency.
Upvotes: 6