c++ - Declaring an array inside typedef struct -


i'm trying declare array inside typedef struct this:

typedef struct node {      node[] arr = new node[25]; }; 

but getting error saying "expected identifier" , arr "expected ';'. doing wrong? thank you

you can act 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 class;


and understand, creating node variable call stack overflow ? each node contains 25 nodes each node contains 25 nodes ... etc


i think wanted this

struct node {     static const int arr_size = 25;     node* arr[arr_size]; }; 

Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -