const char *test[4] = { "A1", "A2", "A3", NULL }; Mon_bouton = new puButtonBox (10, 90, 10, 15, const_cast<char**>(test), TRUE); et là plus de warning et je compile.
int main(void) { const char *test[4] = { "A1", "A2", "A3", 0 }; return 0; }
gcc -W -Wall -ansi -pedantic test.c
g++ -W -Wall -Wabi -pedantic test.cc
j'ai le gcc4.3
et mon fichier est .cpp
j'ai essayé ta manip, mais j'ai toujours le warning et maintenant avec une erreur qui le laisse pas compiler
#include int main(void) { const char *test[4] = { "A1", "A2", "A3", 0 }; for (int i = 0; i < 4; ++i) std::cout << test[i] << std::endl; return 0; }
g++ -W -Wall -Wabi -ansi -pedantic TONFICHIER
#include const char *test[4] = { "xxxxxxxx", "yyyyyyyyyyyyy", "zzzzzzzzzz", 0 }; for (int i = 0; i < 4; ++i) std::cout << test[i] << std::endl;
const char *test[4] = { "xxxxxxxx", "yyyyyyyyyyyyy", "zzzzzzzzzz", 0 }; Mon_bouton = new puButtonBox (10, 90, 10, 15, test, TRUE);
const char *test[4] = { "xxxxxxxx", "yyyyyyyyyyyyy", "zzzzzzzzzz", 0 }; for (int i = 0; i < 4; ++i) std::cout << test[i] << std::endl; Mon_bouton = new puButtonBox (10, 90, 10, 15, test, TRUE);
new puButtonBox (10, 90, 10, 15, test, TRUE)
là mon programme ne se compile plus yikes
puButtonBox my_box = new puButtonBox ( x1, x2, y1, y2, labels, <0|1> ) ;
const char *test[4] = { "A1", "A2", "A3", NULL };
puButtonBox my_box = new puButtonBox ( x1, x2, y1, y2, labels, <0|1> ) ;
const char *test[4] = { "A1", "A2", "A3", NULL };
puButtonBox my_box = new puButtonBox ( x1, x2, y1, y2, labels, <0|1> ) ;
error: no matching function for call to ‘puButtonBox::puButtonBox(int, int, int, int, const char* [4], int)’
/usr/include/plib/pu.h:1488: note: candidates are: puButtonBox::puButtonBox(int, int, int, int, char**, int) <near match>
/usr/include/plib/pu.h:1478: note: puButtonBox::puButtonBox(const puButtonBox&)
puButtonBox(int, int, int, int, char**, int)
puButtonBox(int, int, int, int, const char**, int)
Pour résoudre ceci, j'ai utilisé un "const_cast<char**>(test)" à la place de test dans l'appel de fonction.
Non, c_str() est censé retourner un "const char*". Donc on tourne en rond. Et de plus ce n'est pas "char *" qu'attend le constructeur, mais un "char **".
Je reconnais volontier que le const_cast n'est pas ce qui ce fait de plus beau.
const char *test1[4] = { "Kalman", "Runge Kutta", "Euler", 0 }; const char *test2[3] = { "Capteurs US", "GPS", 0 }; GGP1 = new puButtonBox (10, 90, 10, 15, const_cast <char**>(test1), TRUE); GGP2 = new puButtonBox (10, 70, 10, 15, const_cast <char**>(test2), TRUE);