Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8961941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:00:40+00:00 2026-06-15T16:00:40+00:00

I’ve created a console menu in both C++ and Python, but I suppose the

  • 0

I’ve created a console menu in both C++ and Python, but I suppose the language isn’t in too big role here, since I’m asking about the structure of classes.

So what I’m trying to achieve, is a menu similar to MS-DOS, where I can have parent menus (folders) and action menus (files). Here’s what it could look like in the console, once printed:

[-] Root directory
        Open snakegame
    [-] First sub directory
            Print out stupid messages
        [+] Closed directory in open directory
            Shutdown computer
    [+] These directories are closed
    [+] You can't see the content inside them
        Quit menu

So as you see, I got two types of menus here;

  1. Directory (MS-DOS folder) menus, which hold other menus inside them. When activated, they open/close. For example: Root directory is now open and you can see all the menus inside it. If it gets closed, the [-] turns into [+] and you can’t see any of the other menus.
  2. Action (MS-DOS file) menus, which are linked to a function. When activated, they call the function they’re linked to. For example: Open snakegame could be linked to a function startSnakeGame(), which would close the menu and start the snake game.

I’ve already coded two working implementations to get the wanted result, and I was just wondering, which one should I use? The first way is, where I only have one class called Menu, and it has all the member variables and methods coded into one class. The other way is, where I got these two different types of menus separated into two classes, with a common base class.


Here are some member variables, I’ll split them into three sections (base class, directory class and action class) for now, but they can be combined into one class.

Base Menu:

  • parent = A menu (directory one) that holds this/self inside a list/vector as a child (see below).
  • label = Obviously the label which gets displayed when the menu is printed.
  • selected = Boolean value which tells wether the menu is currently selected (fe. pointed by mouse).

Directory Menu:

  • subMenus = A list or a vector (in C++) that holds other menus inside it.
  • open = A boolean value which tells wether the menu is open or closed.

Action Menu:

  • action = Pointer to the function which gets called when this menu gets activated.

As you can see, there are just few variables which differ from the other class, and it could be set so that if action == 0 (no action) then the menu automatically changes open to false/true depending on it’s current value. This way action menu would be terminated, and only down side would be that action menus would hold subMenus and closed without use.


This might be all about one’s opinion, but I’ve been thinking about this for a while, and couldn’t find one way superior to other, they both have their advantages and downsides, and both work well. So I’m asking about your opinion, and I would love to hear if anyone has any reasons why they’d choose one over the other. Basically I’m asking for the reasons, I don’t care about your opinion.

There will be no other menu types than folder and file, so the base class could not be used for anything else.


Edit: A simple Python and C++ example on how the menus are being used:

Python with only one class:

# Using default param. here to set "action = None" or "action = toggleOpen()"
root = Menu(None, "Root directory")
snake = Menu(root, "Open snakegame", startSnakeGame)
sub1 = Menu(root, "First sub directory")
printMsg = Menu(sub1, "Print out stupid messages")
...

Python with multiple classes:

# With multiple classes, action parameter no longer exists
root = DirectoryMenu(None, "Root directory")
snake = ActionMenu(root, "Open snakegame", startSnakeGame)
...

C++ with one class:

Menu* root = new Menu(0, "Root directory");
Menu* snake = new Menu(&root, "Open snakegame", &startSnakeGame);
...

C++ with multiple classes:

DirectoryMenu* root = new DirectoryMenu(0, "Root directory");
ActionMenu* snake = new ActionMenu(&root, "Open snakegame", &startSnakeGame);
...

2nd Edit: I had only implemented both ways in Python, and only the one-class way in C++. So I started to code the multi-class way in C++ too, just for fun and practice, and I ran into a problem; having one base class, I cannot add this to parent’s subMenus-vector, since base class doesn’t own subMenus, and base class cannot know DirectoryMenu.

So I will have to hack my way through this, which is a BIG minus. Unless someone can think of a good way to implement it?

BaseMenu::BaseMenu(BaseMenu* parent)
: m_parent(parent) // works
{
    m_parent->addSubMenuk(this); // BaseMenu doesn't have Directory's addSubMenu()
}    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:00:42+00:00Added an answer on June 15, 2026 at 4:00 pm

    The two ways are really close to each other in performance etc, so it was kinda hard to figure out.
    However, there was one reason to pick one over the other: Logic and rules in OOP. I had to split it into 3 classes: BaseMenu, ActionMenu and DirectoryMenu.

    Solving the “two classes cannot know each other” problem here could’ve been done like iogane gamba puti fon gu suggested. However, defining abstract methods addSubMenu() and removeSubMenu() in BaseMenu would be just as much against rules as having only one class would, so that’s not an option over the other way.

    What I ended up with, is using callbacks and overloading the pointer(*) operator. It now returns a pointer to the instance of the other class and calls it’s methods depending on the type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.