0

I'm working on a way to Initialize a Menu. Each Menu has Items, an ID, a Title and a Max. Scroll value. I'm trying to design a function with which i can create such a Menu-Layout and store the Details in a struct. I'm looking for something like this:

struct MenuStruct
{
    bool Connected, Open;
    int SelectedClient, Scroll, MaxScroll, ActiveMenu;
    char **Items; // ?
};
MenuStruct Menu[18];

void InitializeMenu(int Client, int MenuID, int MaxScroll, char *Title, char **Items /* ? */)
{
    Menu[Client].ActiveMenu = MenuID;
    Menu[Client].MaxScroll = MaxScroll;
    Menu[Client].Items = Items; // ?
}

void Menu::MainMenu()
{
    InitializeMenu(Client, MainMenuID, 3, "Main Menu", { "Sub Menu 1", "Sub Menu 2", "Sub Menu 3" });
}

As you can probably tell, I'm having problems passing the Items in as paramters and later storing them in the Struct. And while writing this i just thought maybe if someone is able to answer my question, he could maybe tell me aswell, if i could somehow get the Max. Scroll from the number of Items passed in and not having to pass it separately. Thanks in advance!

  • 1
    Why not use `std::vector`? – HolyBlackCat Jul 02 '17 at 18:24
  • @HolyBlackCat i can't. The Project is for XBOX360 and std::vector is not supported on there, already tried. – BasketballPlayer1204 Jul 02 '17 at 18:25
  • 1
    @BasketballPlayer1204 What do you mean by _std::vector is not supported there_? 10 bucks says std::vector is part of the C++ Standard Library. – Ron Jul 02 '17 at 18:27
  • @Ron there simply is no std::vector, it has std::string and such tho. I guess the SDK is outdated. [Proof ^^](https://i.imgur.com/zFQImcO.png) – BasketballPlayer1204 Jul 02 '17 at 18:29
  • @BasketballPlayer1204 What compiler are you using? Take a look at the [The Definitive C++ Book Guide and List](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Ron Jul 02 '17 at 18:29
  • Any particular reason you chose to use `initialize` function instead of using a `constructor`? Additionally - if it *has `std::string`* then why are you using `char*`? – Fureeish Jul 02 '17 at 18:33
  • @Ron the one from vs2010, since the sdk was disigned for vs2010. But i'm sure it can be done with multidimensional char arrays aswell, so rather then discussing about my compiler we could try and solve it this way. – BasketballPlayer1204 Jul 02 '17 at 18:33
  • 1
    @BasketballPlayer1204 I'm pretty sure vs2010 has `std::vector`... – HolyBlackCat Jul 02 '17 at 18:35
  • @Fureeish I'm hooking alot of functions which have char as parameter type and i got tired of using .c_str everytime – BasketballPlayer1204 Jul 02 '17 at 18:35
  • @HolyBlackCat in the 2nd comment above i posted a link, which will proof that i don't have it – BasketballPlayer1204 Jul 02 '17 at 18:36
  • 3
    @BasketballPlayer1204 `#include ` says you owe me 10 bucks. Just kidding. All in good faith. That being said please take the [tour](https://stackoverflow.com/tour) and read the [help page](https://stackoverflow.com/help). – Ron Jul 02 '17 at 18:37
  • 1
    Also, autocompletion might misbehave. Try to actually compile the code. – HolyBlackCat Jul 02 '17 at 18:38
  • @Ron okay i'm now able to use std::vector, so how should i go on, regarding my problem? – BasketballPlayer1204 Jul 02 '17 at 18:40
  • 2
    I'm starting to see how forecefully simplifying work by making an IDE do everything for a programmer is becoming a real issue... Regarding the problem - try to change every `char **` to `std::vector>`, or, as you mentioned not being friends with `string`, go for `std::vector` – Fureeish Jul 02 '17 at 18:41
  • If OP wishes to use char pointers, they should at least be `const char *`. – HolyBlackCat Jul 02 '17 at 18:43

0 Answers0