I'm trying to create a menu using ncurses, I found some useful code and help online, but the code has errors in it. And I can't figure out why I'm generating this error. On top of all this, theres no way I'll be able to use the information I've found until I figure out how to correct this.

here is the code generating the error with a comment pointing to the specific line

while((c = getch()) != KEY_F(1))
   {       switch(c)
     {case KEY_DOWN:
        menu_driver(my_menu, REQ_DOWN_ITEM);
        break;
     case KEY_UP:
       menu_driver(my_menu, REQ_UP_ITEM);
       break;
     case 10: /* Enter */
       {ITEM *cur;
       void (*p)(char *);

       cur = current_item(my_menu);
       p = item_userptr(cur);  //<<<<<<< This line is generating this error:
           //main.cpp:70: error: invalid conversion from `void*' to `void (*)(char*)'

       p((char *)item_name(cur));
       pos_menu_cursor(my_menu);
       break;
       }
       break;
     }
   }

from what I've read online item_userptr() will return a void*

any help would be appreciated

Recommended Answers

All 2 Replies

As long as you are sure that current_item returns a function pointer, you can write:
p=reinterpret_cast<void(*)(char*)>(item_userptr(cur));

Thanks, I might end up needing help beyond this but I think I got it working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.