Share your repls and programming experiences

← Back to all posts
Easy Console Menu in C++
ANDREWVOSS

A header file with code for creating a console menu. The header contains 3 classes 1 of them is a struct but whatever

MenuItem

An item that can be added to a menu. Includes a name, a description, and an action to be run when the item is selected

Menu

The main class you'll be using. Includes a name and description like a MenuItem, as well as some methods.

AddMenu

Adds a submenu to the menu.

AddAction

Adds an item to the menu.

Init

Works all the magic, allowing the user to navigate the menu.

MainMenu

A derived class of Menu that adds an inline wrapper for the Init method.

Example Usage

Voters
DynamicSquid
ANDREWVOSS
Comments
hotnewtop
DynamicSquid

Nice! But try to use const references instead :)

ANDREWVOSS

@DynamicSquid For inheritance, I assume?

DynamicSquid

@ANDREWVOSS No, it's just when you pass by value, you are creating a copy, which is expensive. Passing by const-ref doesn't create unnecessary copies which can hinder performance. You can read more here: https://stackoverflow.com/questions/4986341/where-should-i-prefer-pass-by-reference-or-pass-by-value

ANDREWVOSS

@DynamicSquid Oh, that makes a lot of sense.

CoderGautamYT

Cool :D

ANDREWVOSS
CoderGautamYT