cyclic switching problem
I am forwarding one of the classes in the header of the other in an attempt to solve their cyclic inclusion. Here are my two files:
First file (Parameter.h):
#pragma once #include "Token.h"` class Expression; class Parameter { public: Parameter() { string = new Token(); identifier = new Token(); expr = new Expression(); } Token* string; Token* identifier; Expression* expr; };
Second file (Expression.h):
#pragma once #include "Token.h" #include "Parameter.h" class Expression { public: Expression() { param1 = new Parameter(); param2 = new Parameter(); op = new Token(); } Expression(Parameter* p1, Token* o, Parameter* p2) { param1 = p1; param2 = p2; op = o; } Parameter* param1; Parameter* param2; Token* op; };
As you can see, I forward the Expression expression to Parameter.h, but I still get the following two errors:
forward declaration 'struct Expression'
misuse of the incomplete type 'struct Expression'
I looked through some of the previously asked questions, but still could not solve this problem. Thanks.
source share