Page 1 of 1

Invalid Conversion (C++ question)

Posted: Wed Apr 26, 2006 12:16 pm
by Kon-Tiki
I've got this here code (C++, Allegro and AGUP for the GUI) that's an utter bastard to get to work.

Code: Select all


int translate()
{
    alert("You pushed my button!", "Isn't this a useful feature?", 0,
          "&Yes", "&Definitely", 'y', 'd');

    return D_O_K;
}



(...)

DIALOG main_dlg[] =
{
   /* (dialog proc)     (x)   (y)   (w)   (h) (fg)(bg) (key) (flags)     (d1) (d2)    (dp)                   (dp2) (dp3) */
   
   /* this element just clears the screen, therefore it should come before the others */
   { d_agup_clear_proc,        0,   0,    0,    0,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  },
   


   { d_agup_edit_proc,     100, 75, 160,  8,  0,  0,  0,  0,  LENGTH,   0,  word_1,     NULL,  NULL  },
   { d_agup_push_proc,     100, 95, 100, 20,  0,  0,  0,  0,       0,   0,  str_trans,     0,  translate },
   { quit_proc,              0,  0,   0,  0,  0,  0, 27,  0,       0,   0,       0,        0,  0 },
   
   /* the next two elements don't draw anything */
   { d_yield_proc,        0,   0,    0,    0,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  },
   { NULL,                0,   0,    0,    0,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  }
};
What it does while compiling, is giving this error message:
invalid conversion from `int (*)()' to `void*'
It points to the main_dlg declaration, and seems to be caused by the d_agup_push_proc part.

Re:Invalid Conversion (C++ question)

Posted: Wed Apr 26, 2006 12:16 pm
by Kon-Tiki
(Second part of the post, as it was too long otherwise)
Now, I've checked an example code that does work:

Code: Select all

int surprise()
{
    alert("You pushed my button!", "Isn't this a useful feature?", 0,
          "&Yes", "&Definitely", 'y', 'd');

    return D_O_K;
}

(...)

#define DIS D_DISABLED
#define SEL D_SELECTED


DIALOG main_dlg[] =
{
    /* proc                   x     y     w    h   fg    bg    key  flags    d1    d2  dp                    dp2    dp3 */
    { d_agup_clear_proc,      0,     0, 320, 240,  0,    0,    0,   0,       0,    0,  0,                    0,     0 },

    /* First column */
    { d_agup_check_proc,        5,  25, 100,  12,  0,    0,    0,   SEL,     0,    0,  (void *)"check box",  0,     0 },
    { d_agup_radio_proc,        5,  50, 100,  12,  0,    0,    0,   SEL,     1,    0,  (void *)"radio 1",    0,     0 },
    { d_agup_radio_proc,        5,  75, 100,  12,  0,    0,    0,   0,       1,    0,  (void *)"radio 2",    0,     0 },
    { d_agup_shadow_box_proc,   5, 100, 100,  20,  0,    0,    0,   0,       0,    0,  0,                    0,     0 },
    { d_agup_slider_proc,       5, 125, 100,  12,  0,    0,    0,   0,       100, 50,  0,                    0,     0 },
    { d_agup_edit_proc,         5, 150, 100,  14,  0,    0,    0,   0,       100,  0,  buf2,                 0,     0 },
    { d_agup_list_proc,         5, 175, 100,  50,  0,    0,    0,   0,       2,    0,  lister,               sel2,  0 },

    /* Buttons */
    { d_agup_button_proc,     110,  25, 100,  20,  0,    0,    0,   0,       0,    0,  (void *)"button",     0,     0 },
    { d_agup_push_proc,       110,  50, 100,  20,  0,    0,    0,   0,       0,    0,  (void *)"button",     0,     surprise },
    { d_agup_button_proc,     215,  25, 100,  20,  0,    0,    0,   DIS,     0,    0,  (void *)"button",     0,     0 },
    { d_agup_button_proc,     215,  50, 100,  20,  0,    0,    0,   DIS|SEL, 0,    0,  (void *)"button",     0,     0 },

    /* Misc */
    #define ICON_DIALOG 12
    { d_agup_icon_proc,       240,  75,  50,  50,  0,    0,    0,   0,       2,    2,  0,                    0,     0 },
    { d_agup_text_proc,       240, 130,  75,  12,  0,    0,    0,   0,       0,    0,  (void *)"A",          0,     0 },
#if (ALLEGRO_VERSION == 4) && (ALLEGRO_SUB_VERSION == 0)
    /* Allegro 4.0 had a severely broken ctext_proc. */
    { d_agup_ctext_proc,      240 + 75 / 2, 150,  0,  12,  0,    0,    0,   0,       0,    0,  (void *)"B",          0,     0 },
#else
    { d_agup_ctext_proc,      240, 150,  75,  12,  0,    0,    0,   0,       0,    0,  (void *)"B",          0,     0 },    
#endif
    { d_agup_rtext_proc,      240, 170,  75,  12,  0,    0,    0,   0,       0,    0,  (void *)"C",          0,     0 },
    { d_agup_textbox_proc,    110,  75, 100, 150,  0,    0,    0,   0,       0,    0,  buf3,                 0,     0 },
    { d_agup_slider_proc,     215,  75,  12, 100,  0,    0,    0,   0,       100, 50,  0,                    0,     0 },
    { d_agup_box_proc,        215, 185, 100,  20,  0,    0,    0,   0,       0,    0,  0,                    0,     0 },
    { d_agup_slider_proc,     215, 213, 100,  12,  0,    0,    0,   DIS,     100,  0,  0,                    0,     0 },
    { d_agup_menu_proc,         5,   5, 310,  12,  0,    0,    0,   0,       0,    0,  menubar,              0,     0 },
    { quit_proc,              0,     0,   0,   0,  0,    0,    27,  0,       0,    0,  0,                    0,     0 },
    { d_agup_text_proc,       0,   232, 320,   8,  0,    0,    0,   0,       0,    0,  version,              0,     0 },
    { d_yield_proc,           0,     0,   0,   0,  0,    0,    0,   0,       0,    0,  0,                    0,     0 },
    { NULL,                   0,     0,   0,   0,  0,    0,    0,   0,       0,    0,  0,                    0,     0 }
};
That does work. I don't see what I've done wrong :? Anybody able to help me out on this one?

Re:Invalid Conversion (C++ question)

Posted: Wed Apr 26, 2006 2:51 pm
by Kon-Tiki
Nevermind. Figured it out. Apparently, C++ is alot less tolerant toward types than C, so had to manually typecast the translate function call with (void *)

Re:Invalid Conversion (C++ question)

Posted: Thu May 04, 2006 1:26 am
by Solar
Kon-Tiki wrote: Apparently, C++ is alot less tolerant toward types than C...
Correct, by spec and by design. A Good Thing (tm), IMHO.

Re:Invalid Conversion (C++ question)

Posted: Thu May 04, 2006 9:49 am
by Kon-Tiki
Yep, but it's a huge difference when you come from a language that automatically casts and converts, like PHP. My program's pretty much done now. Just got to alter the translation query so that it'll search for any entry containing the string that's put in, instead of any entry which has exactly that string as contents, and the possibility to load in different language databases. Oh, and maybe the possibility to print out your word list. If anybody's interested in seeing what it is so far, I'd be more than happy to share it with y'all :)