Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

allocation d objet dynamique.

1 réponse
Avatar
charles.de-izarra
salut j ai un probleme avec un prog qui crash lorsque j initialise un objet
de type boutton.
ma classe ressemble a ca:
************************************
class bitbut{
public:
BITMAP *button;
int x,x1,y,y1;
BITMAP *buttonc;
int (*test)();
bitbut();
bitbut(BITMAP *bmp,BITMAP *bmp2,int X,int X1,int Y,int Y1);
bitbut(BITMAP *bmp,BITMAP *bmp2,int X,int Y);
bitbut(BITMAP *bmp,int X,int Y);
};
***********************************
j utilise des fonction pour afficher et cliquer mes bouttons:
int bitbutclic(bitbut *tab[],int tailletab){
for (int i=0;i<tailletab;i++){
if (mouse_x>=tab[i]->x && mouse_x<=tab[i]->x1 && mouse_y>=tab[i]->y &&
mouse_y<=tab[i]->y1 && mouse_b & 1 )
{
tab[i]->test();
}
}
return 0;
};


mon initialisation de tablo d objet en dyna ressemble a ca:
bitbut *array[2];//declaration

array[0]=new bitbut(image1,image2,X,Y);
array[1]=new bitbut(image1,image2,X,Y);

c mon allocation qui est movaise?
comment faire pour faire une allocation dyna de tableau d objets

1 réponse

Avatar
Horst Kraemer
On Wed, 28 Apr 2004 13:19:34 +0200, "charles.de-izarra"
wrote:

salut j ai un probleme avec un prog qui crash lorsque j initialise un objet
de type boutton.
ma classe ressemble a ca:
************************************
class bitbut{
public:
BITMAP *button;
int x,x1,y,y1;
BITMAP *buttonc;
int (*test)();
bitbut();
bitbut(BITMAP *bmp,BITMAP *bmp2,int X,int X1,int Y,int Y1);
bitbut(BITMAP *bmp,BITMAP *bmp2,int X,int Y);
bitbut(BITMAP *bmp,int X,int Y);
};
***********************************
j utilise des fonction pour afficher et cliquer mes bouttons:
int bitbutclic(bitbut *tab[],int tailletab){
for (int i=0;i<tailletab;i++){
if (mouse_x>=tab[i]->x && mouse_x<=tab[i]->x1 && mouse_y>=tab[i]->y &&
mouse_y<=tab[i]->y1 && mouse_b & 1 )
{
tab[i]->test();
}
}
return 0;
};


mon initialisation de tablo d objet en dyna ressemble a ca:
bitbut *array[2];//declaration

array[0]=new bitbut(image1,image2,X,Y);
array[1]=new bitbut(image1,image2,X,Y);

c mon allocation qui est movaise?


Ce qu'on voit n'est pas faux, mais on ne voit pas le code des
constructeurs.


comment faire pour faire une allocation dyna de tableau d objets


Chez toi il ne s'agit pas d'un tableau d'objets mais d'on tableau de
pointeurs d'objet.


bitbut **array = new bitbut*[10];

for (int i=0;i<10;++i)
array[i]=new bitbut(image1,image2,X,Y);

...

for (int i=0;i<10;++i)
delete array[i];
delete [] array;

--
Horst