après avoir lu le cours de C++ du site j'ai voulu modifier mon code de façon à libérer la mémoire alouée dynamiquement.
J'ai donc créé deux tableaux de 32 de type CCaseblance et CCasenoire de manière à pouvoir les "deleté" dans mon destructeur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifndef CECHIQUIER_H #define CECHIQUIER_H #include <gtkmm.h> #include <iostream> #include "CCaseblanche.h" #include "CCasenoire.h" class CEchiquier : public Gtk::Table { public: //constructeur et destructeur CEchiquier(); virtual ~CEchiquier(); void affiche(); protected: CCasenoire *m_ptabnoire; CCaseblanche *m_ptabblanche; }; #endif //CECHIQUIER_HSi je modifie mon code avec ce qui est rouge, la compilation va très bien mais quand je lance le prog, Bug buddy prend la main et génère un fichier erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include "CEchiquier.h" CEchiquier::CEchiquier():Table(10,10,true),m_ptabnoire(new CCasenoire[32]),m_ptabblanche(new CCaseblanche[32]) { //int index=-1; for(int j=1;j<9;j+=2){ for(int i=1;i<9;i+=2){ attach(*new CCaseblanche,i,i+1,j,j+1);-->attach(m_ptabblanche[index++],i,i+1,j,j+1); attach(*new CCasenoire,i+1,i+2,j,j+1);-->attach(m_ptabnoire[index++],i,i+1,j,j+1); } } for(int j=2;j<9;j+=2){ for(int i=1;i<9;i+=2){ attach(*new CCasenoire,i,i+1,j,j+1);-->attach(m_ptabnoire[index++],i,i+1,j,j+1); attach(*new CCaseblanche,i+1,i+2,j,j+1);-->attach(m_ptabblanche[index++],i,i+1,j,j+1); } } std::cout<<"m_ptabblanche[1]: "<< m_ptabblanche[1]<<std::endl; affiche(); show_all_children(); } CEchiquier::~CEchiquier() { delete m_ptabnoire; delete m_ptabblanche; }
Quequ'un aurait-il une idée?[?1034hUsing host libthread_db library "/lib64/libthread_db.so.1".
0x0000003518c9a835 in waitpid () from /lib64/libc.so.6
#0 0x0000003518c9a835 in waitpid () from /lib64/libc.so.6
#1 0x00000035d9e5e4c0 in g_spawn_sync () from /lib64/libglib-2.0.so.0
#2 0x00000035d9e5e7b8 in g_spawn_command_line_sync ()
from /lib64/libglib-2.0.so.0
#3 0x00002aaaaf7a23cd in Gtk::Widget::show_all_vfunc ()
from /usr/lib64/gtk-2.0/modules/libgnomebreakpad.so
#4 <signal handler called>
#5 0x00000037572e2b33 in Gtk::Table::attach ()
from /usr/lib64/libgtkmm-2.4.so.1
#6 0x0000000000408a13 in CEchiquier (this=0x6b8380)
at /home/...CEchiquier.cc:9
#7 0x000000000040a3cb in CGnomeapp (this=0x7fff610fb4d0)
at /home/.../CGnomeapp.cc:27
#8 0x000000000040b7e9 in main (argc=1, argv=0x7fff610fb878)
at /home/.../main.cc:13
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Partager