473,624 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Menu class help!

2 New Member
I built this class for simple text based menu, for using with other classes.

#ifndef MENU_H
#define MENU_H

#include <string>
using std::string;

#include <vector>
using std::vector;

#include "misc.h"

template <class MyClass>
struct Option
{
string labbel;
void (MyClass::*func tion)(void);
};


template <class MyClass>
class Menu
{
private:
string title;
string exit_labbel;
vector< Option<MyClass> > options;

public:
// Constructor
Menu(const string& title, const string& exit_labbel);

// Destructor
~Menu(void){};

// Adicionar Opcao
void AddOption(const string& labbel, void (MyClass::*func ao)(void));

// Ligar o menu
void Start() const;

};


template <class MyClass>
Menu<MyClass>:: Menu(const std::string &title, const std::string &exit_labbel ):
title(title),
exit_labbel(exi t_labbel)
{
}


template <class MyClass>
void
Menu<MyClass>:: AddOption(const std::string &labbel, void (MyClass::*func tion)(void))
{
Option<MyClass> option;
option.labbel = labbel;
option.function = function;
options.push_ba ck(option);
}


template <class MyClass>
void
Menu<MyClass>:: Start() const
{
cout << endl << '[' << title << ']' << endl;

unsigned numoption = 1;

for(unsigned i = 0; i != options.size(); ++i)
{
cout << " * " << numopcao << " - " << options[i].labbel << endl;
numoption++;
}

cout << " * 0 - " << exit_labbel << endl;

std::cin >> input;

if( input == 0 )
return;
else
{
options[input - 1].function;
}

Start();
}

#endif

This thing compiles, and functions are working but when I choose some option, it just calls Start again without calling the option I choose.
Can someone help me :P ?
Nov 27 '06 #1
1 3605
teofilo
2 New Member
example of use

class Thing
{
public:

Menu main_menu;

void dosomething(voi d)
{
std::cout << "It's working!" << std::endl;
}

Thing(): main_menu("Main Menu","Exit Program")
{
main_menu.AddOp tion("Do Something",&dos omething);
}

void SeeMenu(void)
{
main_menu.Start ();
}

};

Thing any;

any.SeeMenu();
Nov 27 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2482
by: Macamba | last post by:
Hi all, I am currently developing a website for a voluntary organisation. It is my first step in website development. The dynamic menu I developed has some bugs, which I addressed in another post. In this post I want to ask you why my code behaves differently in IE, while it behaves like I expect in Mozilla and Opera. What I would like to see addressed is what I need to do to get the same behaviour in all 3 browsers. I know each browser...
0
16153
by: vikram.cvk | last post by:
Hello Experts, Im trying to design a CSS vertical drop down menu which should have the following functionality. Home About Us | -->Overview
2
3874
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it is a server problem but was told it is not possible, therefore assuming it is a client script problem? the script works last time...
4
8350
by: Rabel | last post by:
I am not very good at javascript I mostly am a flash developer but I am trying to apply one of our old expanding menus to work for a new site but it doesn't collapse the way I need it to right now the code I am using looks like this function openSubCategory(n, nn) { var i = 0 for(i=1;i<n+1;i++) { var sel = document.getElementById('insideSubCategory'+i); sel.style.display = 'none';
2
1767
by: SiNi | last post by:
Hello. I am an italian student and I do not known javascript language. I need your help! I have built a web page with frames (left frame and main frame). In the left frames I have attach the code that you find below. I have a problem. because I am not able...when I choose a voice in the menu, the relative web page open in the left menu....where there is the menu; but
2
2265
by: Ravi Joshi | last post by:
The menu on my site works fine in IE6 and Firefox. In IE7, there is a problem with the menu: when you mouse over the various main catagories, the sub-catagories all appear to the right as they should; however, as soon as you mouse towards any but the TOP sub-catagory, all those sub-catagories still view there. It will work first time quite fine..but if user clicks outsite anywhere in screen then this problem occur.. i think it's css...
2
1413
by: fjohnson | last post by:
Hello, I have a CSS Horizontal dropdown menu and the drop down menu is pushed to the right instead of directly underneath the heading. I am completely new to CSS and I do not yet know exactly what I am looking at in the CSS file. Any idea on how I can get it positioned correctly? Coding as follows: CSS style sheet: -------------------------------------------------------- /* Begin CSS Drop Down Menu */ #menu { width: 100%;
2
4174
by: dharmbhav | last post by:
Hello all, I am trying to develop a roll-over menu effect on a page. It works fine with all other browsers except IE6. Can some one please help me? HTML: <div class="menu-item-wrap"> <a href="#" class="menu-item-text"> Menu1 </a>
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.