I'm fairly new to c++ so i'm having a bit of trouble wrapping my head around forward declarations.
I have two header files which #include
eachother as they both have structs that reference eachother. I've seen from many other answers that I need to forward declare these structs, so that I can do this. Here is how i implemented that:
Parser.h
namespace Variables
{
struct Variable;
}
#include "variables.h"
namespace Parser
{
struct Node
{
int type;
Variables::Variable variable;
int skip;
Parser::Function fn;
Parser::Node *parent;
};
}
Variables.h
namespace Parser
{
struct Node;
}
#include "parser.h"
namespace Variables
{
typedef struct Variable
{
int type;
std::string name;
Variables::Expression int_value;
int scope;
Parser::Node *parent;
} Variable;
}
This seemed to work, however it complained about the Node struct having a member of incomplete type(the Variables::Variable) which I found out was because you have to do a const value when it's forward declared, so I made it a pointer:
struct Node
{
int type;
Variables::Variable *variable;
int skip;
Parser::Function fn;
Parser::Node *parent;
};
Is there a way that I can implement this where I don't have to make Variables::Variable
a pointer?