473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Menu class help!

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::*function)(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::*funcao)(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(exit_labbel)
{
}


template <class MyClass>
void
Menu<MyClass>::AddOption(const std::string &labbel, void (MyClass::*function)(void))
{
Option<MyClass> option;
option.labbel = labbel;
option.function = function;
options.push_back(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 3595
example of use

class Thing
{
public:

Menu main_menu;

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

Thing(): main_menu("Main Menu","Exit Program")
{
main_menu.AddOption("Do Something",&dosomething);
}

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
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...
0
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
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...
4
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...
2
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...
2
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...
2
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...
2
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">...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...

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.