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];
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.