I'm new to cpp since a few days and struggling with the following definition:
struct menuItem {
char* name;
int value;
};
struct topMenu {
int menuIcon;
char* Name;
menuItem item[];
};
topMenu menuRoot[] = {
{ 0, "File",
{"Open ...", 1},
{"New ...", 4},
{"Close", 1},
{"Exit", 3}
},
{ 0, "Edit",
{"Cut ", 3},
{"Copy", 8},
{"Paste", 2},
{"Find", 1},
{"Replace", 6}
},
{ 0, "Help",
{"Help", 7},
{"About", 9},
{"Update ..", 9}
}
};
I receive the error
33:1: error: too many initializers for 'menuItem [0]'
33:1: error: too many initializers for 'topMenu'
33:1: error: too many initializers for 'menuItem [0]'
33:1: error: too many initializers for 'topMenu'
33:1: error: too many initializers for 'menuItem [0]'
33:1: error: too many initializers for 'topMenu'
Sorry, i'm a little bit stuck ... maybe its just to late :) Thanks in advance.
char*to point to string literals. It was deprecated in C++03 and removed in C++11. Either use aconst char*or astd::string/std::string_view{({{"Help", 7}, {"About", 9}, {"Update ..", 9}}).menuItem item[];? should it bestd::vectorinstead?menuItem item[];is not allowed in Standard C++, you must specify a size (or use a different construct altogether)