#recursive structs
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
you need to forward declare it
do you mean to move struct b before struct a?
no, thats not a forward declaration
;compile
struct a{
struct b* ptr;
int a, b, c;
};
struct b
{
struct a a_val;
};
wait a minute
struct Foo; // declaration
// use Foo* or Foo&
struct Foo { // provide definition somewhere
};
``` is the typical route
This already compiles
But this is written in C style. In C++ you'd typically write it as
struct a{
b* ptr;
int a, b, c;
};
struct b
{
a a_val;
};
And this indeed doesn't compile until you add struct b; at the beginning before the first struct
oh it was in c++
The C style works in C++ as well
I will show you my code
The C style works in C++ as well
It just looks ugly
yeah, my actual code is in c++ but kind of like c
I haven't done that in my original code
I will sent it to you right now
struct ElifConditionals
{
Value* exp;
Program block;
// ElifConditionals(**& v_exp, Program*& v_block)Value*:exp(v_exp), block(v_block){
// Node = NodeType::ElifConditionals_;
// }
};
struct ElseConditionals
{
Program block;
// ElseConditionals(Program*& v_block):block(v_block){Node = NodeType::ElseConditionals_; }
};
struct Value
{ // types of expression
// statements
NodeType Node;
union
{
E_O_F eof;
Program program;
//VarDec varDec;
//VarConstDec varConstDec;
//Conditionals conditionals;
//ElifConditionals
//ElseConditionals,
// both literals(value) and expressions
BoolLiteral boolLiteral;
IntLiteral intLiteral;
NullVal nullval;
// expressions
AssignExpr assignExpr;
Identifier identifier;
BinaryArithExpr binaryArithExpr;
BinaryBoolExpr binaryBoolExpr;
BinaryBoolNumExpr binaryBoolNumExpr;
};
};
it gives me error
src/Headers/../FrontEnd/Headers/AST.h:124:3: error: ‘Value’ does not name a type
124 | Value* exp;
| ^~~~~```
Read the end of this message
so what is wrong with my code
it is compiled in c++
Read the last sentence of the message I linked