Alfredo
Alfredo

Reputation: 1

C++ refer at const pointer before declare it

I'm creating a menu and this menu is treestructure, here there is the code

typedef struct itemMenu{
    uint8_t id;
    char item[15];
    struct itemMenu *next;
};

const itemMenu menu0[] PROGMEM =
{
{1, "item1", menu1},
{2, "item2", 0},
{3, "item3", 0},
{0, "\n", 0}};

const itemMenu menu1[] PROGMEM =
{
{1, "item1", 0},
{0, "\n", menu0}};

The submenu is linked to the main one, the index (first field) 0 means reference to the previus menu. When I compile it, there is an error because the reference at menu1 is not possible on the first array. Is it possible to announce the menu1 before the declaration?

Upvotes: 0

Views: 68

Answers (1)

catnip
catnip

Reputation: 25388

You can put:

extern const itemMenu menu1[];

before the definition of menu0.

Please note that there are a number of other errors in the code, however. In particular, with the code as written, this:

struct itemMenu *next;

needs to be changed to this:

const struct itemMenu *next;

or more simply:

const itemMenu *next;

Upvotes: 3

Related Questions