lapique@siisg1.epfl.ch (Lapique Francis) (03/28/91)
#include <stdio.h> #include <stdarg.h> #include <string.h> class event { public: virtual void activate(void) { printf("No operation\n"); } }; class menu : public event { event **entries; int num_items; public: int cur_item; menu(int nitems,...); void activate(void); }; menu::menu(int nitems,...) { va_list arg_ptr; int i; entries = new event *[ num_items = nitems]; va_start(arg_ptr,nitems); for ( i=0; i <num_items;i++) { entries[i] = va_arg(arg_ptr,event *); } va_end(arg_ptr); cur_item = 0; } void menu::activate(void) { printf("Enter a value item: "); scanf("%d",&cur_item); printf("\n"); if ( cur_item > 0 && cur_item <= num_items ) { entries[cur_item-1]->activate(); } else { printf ("Invalid selection\n"); activate(); } } class sample_event : public event { char report [80]; public: sample_event (char *rep) { strcpy(report,rep); } void activate(void) { printf("%s\n",report); } }; void main() { sample_event esckey ( "ESC OK" ); sample_event leftmouse ("leftmouse OK"); menu queue(2,&esckey,&leftmouse); queue.activate(); } Now I would like to execute a function "f1" when the item 1 is enter, and do something like "value = 1" when the item 2 is enter. What is the best way to do that ? F.Lapique ------------------------------------------------------------ F.Lapique lapique@sic.epfl.ch/lapique@siisg1.epfl.ch Swiss Federal Institute of Technology- Lausanne tel (+41-21) 693.45.96 ------------------------------------------------------------