Format to access a class function pointer which is a member of a struct

Pranav Singhania (11)
Below is my struct declaration where
ticket_booking
is my class.
1
2
3
4
5
6
7
struct MENUITEM {
      enum ITEMTYPE type;
      char *name;
      char *helpstring;
      void (ticket_booking :: *p)();
      void *s;
};


And now below I want to access the class function pointer which doesn't seem to be happening
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
      case CR:
            {		
		 struct MENUITEM *itemp = mp->menuitemlist[mp->curritem];
                  if(itemp->type == MI_PARENT)
                  {
			struct MENU *mp2 = (struct MENU*) itemp->(ticket_booking :: *p) (); //ERROR 1
                        displaymenu(mp);
                        mp = mp2;
                  }
                  else if(itemp->type == MI_ACTION)
                  {

			fp = (void(*) ()) itemp->(ticket_booking :: *p) (); //ERROR 2
                    fp();
                  }
            }
			break;


I tried all possible ways but none seem to work and this is causing the whole project to go flat. Immediate suggestion would help, not very familiar with class function pointers.
Last edited on
vince1027 (137)
Read this: http://www.parashift.com/c++-faq/pointers-to-members.html

In general, don't keep a reference to member functions; keep a reference to the instance instead. You cannot invoke a member function without the instance it needs to invoke on (because the this context would be meaningless). Keeping a reference to the instance not only makes this easier but also make your code readable and easier to understand for others.
Registered users can post here. Sign in or register to post.