This is just a part of the standard C++ convention, but it's still useful in your case.
QuoteHow should I actually get the type of my MenuItem? Lets say I want to find the options SubMenu and add some ActionItems at runtime
Also you should probably use objects than just pointers to objects in a vector<> . This way you reduce memory usage and a vector actually cleans itself automatically when out of range.
This could lead to loss of pointers, which can bring to confusion as smarter pointers are defined as "better"("smarter") by C++ standard than new and delete.
Smart pointers prevent you from having too many pointers with complicated connections across data structures(functions). Also they are always automatically deleted when completely out of scope.
Nodes are parts of a linked list, so you should make a link list structure(just a match map in Unreal Tournament 2004 - Onslaught mode).
A node represents a part of a linked list, but it is also a building block of a linked structure.
Linked nodes in the aforementioned Onslaught mode work independently. They are linked to each other, but each of them contains their own independent information.
Nodes connect between each other, they check other nodes like connected to other nodes. However, making such a structure can very expensive what regards implementation time investment and RAM usage.
So my suggestion would be, use the independence of each node. So whenever a node's link has changed, only the array of connections is changed, meaning before the connected node, it was set from one third note
If both second and third are connected to the first node, you would apply the same process as the third node is independent as well.
I have tried this: (personal preference, but I'm making a menu system in my console-text game myself) :P
main.cpp
int main()
{
//load menus from data files here
Menu submenu1;
submenu1.addOption("New game");
MenuSystem menu(submenu1, 1);
for (;;)
{
menu.loop();
if (menu.getExit())
{
break;
}
}
}
Menu.h
#include <iostream>
#include <vector>
class Menu
{
std::vector<std::string> options;
int id{ 0 }; //sort through
int target_id{ 0 };
};
MenuSystem.h
#pragma once
#include "Menu.h"
class MenuSystem
{
std::vector<Menu> menu_list;
int number_of_menus{ 0 };
const int starting_menu{ 1 };
static bool exit;
int current_menu{ starting_menu };
int current_target{ 0 };
//sort through menu IDs
};
I would do this:(in your case)
Basically you get the Node name, by sorting through using its private: data identifier and once you get the correct ID,
take the std::string from the Node which contains the node's name.