diff options
Autocommit at 01.05.2022 @ 10:21
2 files changed, 10 insertions, 6 deletions
| -rw-r--r-- | src/ConsoleInterface/Menu.cpp | 11 | ||||
| -rw-r--r-- | src/List/List.cpp | 5 |
diff --git a/src/ConsoleInterface/Menu.cpp b/src/ConsoleInterface/Menu.cpp index 27471a6..669fb6c 100644 --- a/src/ConsoleInterface/Menu.cpp +++ b/src/ConsoleInterface/Menu.cpp @@ -2,19 +2,22 @@ #include "Toolbox.h" Menu::Menu(const Command* commands, unsigned commandCount) { - menuOptions = List<Command>(); - for (unsigned i = 0; i < commandCount; i++) - menuOptions.add(commands[i]); + menuOptions = List<Command>(commands, commandCount); } void Menu::navigate() const { + if (menuOptions.get_count() == 0) { + std::cout << "Menu is empty!" << std::endl; + return; + } + resetOrderedList(); for (unsigned i = 0; i < menuOptions.get_count(); i++) printOrderedListElem(menuOptions[i].get_nameInMenu()); unsigned buffer = 0; while (0 == buffer || buffer >= menuOptions.get_count()) { - std::cout << "Execute No [0-" << menuOptions.get_count() << "]: "; + std::cout << "Execute No [1-" << menuOptions.get_count() << "]: "; std::cin >> buffer; } diff --git a/src/List/List.cpp b/src/List/List.cpp index fbd3288..bdb9b4a 100644 --- a/src/List/List.cpp +++ b/src/List/List.cpp @@ -29,8 +29,9 @@ void List<T>::copyFrom(const List& other) { /* Public */ template <class T> -List<T>::List(const T* elements, unsigned elementsCount) { - +List<T>::List(const T* elements, unsigned elementsCount) : List() { + for (unsigned i = 0; i < elementsCount; i++) + add(elements[i]); } template <class T> |
