 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
charles.de-izarra Guest
|
Posted: Wed Apr 28, 2004 11:19 am Post subject: allocation d objet dynamique. |
|
|
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
|
|
| Back to top |
|
 |
Horst Kraemer Guest
|
Posted: Sat May 01, 2004 1:55 pm Post subject: Re: allocation d objet dynamique. |
|
|
On Wed, 28 Apr 2004 13:19:34 +0200, "charles.de-izarra"
<charles.de-izarra (AT) wanadoo (DOT) fr> wrote:
| Quote: | 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.
| Quote: | 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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|