I'm on prgramming a menu for an 16x2 LCD for a small arduino project. I'm nearly finished, but i do not understand the last small issue.
The following (simplified) code generates the problem:
int var1=0;
int var2=0;
typedef struct {
unsigned int item_value;
char item_name[17];
} Select_Item;
typedef struct {
char item_name[17];
int* variable;
Select_Item* list;
} Menu_Item;
Select_Item sel_one = { 0, "Selection 1" };
Select_Item sel_two = { 1, "Selection 2" };
Select_Item* sel_list[2] = { &sel_one, &sel_two };
Menu_Item menu_item1 = { "Item 1", &var1, NULL };
Menu_Item menu_item2 = { "Item 2", &var2, &sel_list };
Menu_Item* menu_list[2] = { &menu_item1, &menu_item2 };
It ends up with the following error:
sketch_feb08a.ino:24:53: error: cannot convert 'Select_Item* (*)[2]' to 'Select_Item*' in initialization
In the code i'm accessing the values from the variables and show it in the display and once edited i can write it back to the variable. That was not the problem as long as i had just numbers to show/edit. Now for ease of use i wanted to add some kind of option menu, where the user can choose from the options. The item_name should be displayed, instead of the raw value, but of course the item_value should be used behind the scene. That is why i introduced the Select_Item struct.
I don't understand the error message. What's wrong here?
&sel_listis a pointer-to-array, orSelect_Item * (*)[2]. WhereasMenu_Item::listis a pointer-to-Select_ItemorSelect_Item *.sel_listwithout the address-of (&) operator.