I'm trying to declare an array inside a typedef struct like this:
typedef struct Node {
Node[] arr = new Node[25];
};
But I am getting an error saying "expected an identifier" and that arr "expected a ';'. What am I doing wrong? Thank you
you can act like this
struct Node {
static const int arr_size = 25;
Node* arr;
Node() { arr = new Node[arr_size]; }
~Node() { delete[] arr; }
};
you re not allowed initialzie non const int varizbles inside the class;
and do you understand, that creating a node variable will call stack overflow ? Each node contains 25 nodes where each node contains 25 nodes ... etc
i think you wanted something like this
struct Node {
static const int arr_size = 25;
Node* arr[arr_size];
};
Node arr[25]Nodes in aNode?Node. AndNodeis not complete type until the end of the class definnition, so you can't donew Node[25]inside the class definition.