Bonjour,
J'ai une erreur bizzard lors de l'exécution de mon programme après avoir rajouté
cette ligne dans mon destructeur : delete [] T;
voici le programme
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 #include "NuageDePoints.h" #include <iostream> #include<math.h> #include<stdlib.h> #include<string> #include <time.h> using namespace std; // get an random float between 0 and 1 int NuageDePoints::getRand() { srand(time(NULL)); int nombre =(rand() % 11 ); return nombre; } NuageDePoints::NuageDePoints(int _nb) { nb= _nb; T= new Point[nb]; for(int i=0; i<nb ; i++) { int a=((getRand()*17)%11); int b=getRand(); T[i].SetXPoint(a); T[i].SetYPoint(b); for(int j=0 ; j<i ; j++) { if(T[i].testEgual(T[j])) { a=((getRand()*13)%11); b=getRand(); T[i].SetXPoint(a); T[i].SetYPoint(b); j=0; } } } } void NuageDePoints::SetPoint( Point p , int e ) { T[e].SetXPoint(p.X()); T[e].SetYPoint(p.Y()); } Point NuageDePoints::getP(int e) const { return T[e-1]; } int NuageDePoints::getSize() const { return nb; } NuageDePoints NuageDePoints::operator+(const Point& p) { NuageDePoints nuage_temp(nb+1); for(int i=0;i<nb;i++) { nuage_temp.SetPoint(T[i],i); } nuage_temp.SetPoint(p,nb); return nuage_temp; } NuageDePoints operator+(const Point& point , const NuageDePoints& nuage) { NuageDePoints nuage_temp((nuage.getSize())+1); for(int i=0;i<(nuage.getSize());i++) { nuage_temp.SetPoint(nuage.getP(i+1),i); } nuage_temp.SetPoint(point,(nuage.getSize())); return nuage_temp; } NuageDePoints operator-(const NuageDePoints& nuage, const Point& point) { NuageDePoints nuage_temp(nuage.getSize()-1); for(int i=0;i<((nuage_temp.getSize()));i++) { if(!(nuage.getP(i+1).testEgual(point))) { nuage_temp.SetPoint(nuage.getP(i+1),i); } } return nuage_temp; } void NuageDePoints::getNuage() { for(int i=0; i<nb;i++) { cout<<"point"<<(i+1)<<"\t"<<T[i].X()<<","<<T[i].Y()<<endl; } } void NuageDePoints::barycentre() { float tmp_x=0; float tmp_y=0; for(int i=0;i<nb;i++) { tmp_x= tmp_x + T[i].X(); } for(int j=0;j<nb;j++) { tmp_y= tmp_y + T[j].Y(); } tmp_x= (tmp_x / nb ); tmp_y= (tmp_y / nb); cout<<"barycentre du nuage de points:"<<endl; cout<<"barycentre:\tx=" << tmp_x <<"\t,\ty="<<tmp_y<<endl; } NuageDePoints::~NuageDePoints() { delete [] T; cout<<"supprimer\t"<<endl; }
voici mon main :
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 #include "NuageDePoints.h" int main() { Point p(2,4); Point a(3,2); // monpoint.Norme(monpoint,second); // monpoint.testEgual(second); // toto.barycentre(); NuageDePoints newnuage(5); NuageDePoints newnuage2(6); newnuage.getNuage(); newnuage2=newnuage+a; newnuage2.getNuage(); newnuage= newnuage2 -a ; newnuage.getNuage(); }
et à l'éxecution il me met sa à la fin ! :
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 e********@@**-***-**% test point1 6,1 point2 2,1 point3 10,5 point4 8,5 point5 10,2 supprimer point1 6,1 point2 2,1 point3 10,5 point4 8,5 point5 10,2 point6 3,2 supprimer point1 6,1 point2 2,1 point3 10,5 point4 8,5 point5 10,2 *** glibc detected *** test: double free or corruption (fasttop): 0x08b8c070 *** ======= Backtrace: ========= /lib/i686/cmov/libc.so.6(+0x6b321)[0xb74d9321] /lib/i686/cmov/libc.so.6(+0x6cb78)[0xb74dab78] /lib/i686/cmov/libc.so.6(cfree+0x6d)[0xb74ddc5d] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb76b5721] /usr/lib/libstdc++.so.6(_ZdaPv+0x1d)[0xb76b577d] test[0x804957d] test[0x8049a78] /lib/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb7484c76] test[0x8048881] ======= Memory map: ======== 08048000-0804b000 r-xp 00000000 00:17 52059210 /amd/ladyburn/ubs/ladyburn/home.1/1/e0800401/Mes documents/L3/Semestre 5/INF1508C++/TP05/test 0804b000-0804c000 rw-p 00002000 00:17 52059210 /amd/ladyburn/ubs/ladyburn/home.1/1/e0800401/Mes documents/L3/Semestre 5/INF1508C++/TP05/test 08b8c000-08bad000 rw-p 00000000 00:00 0 [heap] b7300000-b7321000 rw-p 00000000 00:00 0 b7321000-b7400000 ---p 00000000 00:00 0 b746d000-b746e000 rw-p 00000000 00:00 0 b746e000-b75ae000 r-xp 00000000 08:03 331787 /lib/i686/cmov/libc-2.11.2.so b75ae000-b75af000 ---p 00140000 08:03 331787 /lib/i686/cmov/libc-2.11.2.so b75af000-b75b1000 r--p 00140000 08:03 331787 /lib/i686/cmov/libc-2.11.2.so b75b1000-b75b2000 rw-p 00142000 08:03 331787 /lib/i686/cmov/libc-2.11.2.so b75b2000-b75b5000 rw-p 00000000 00:00 0 b75b5000-b75d2000 r-xp 00000000 08:03 331322 /lib/libgcc_s.so.1 b75d2000-b75d3000 rw-p 0001c000 08:03 331322 /lib/libgcc_s.so.1 b75d3000-b75d4000 rw-p 00000000 00:00 0 b75d4000-b75f8000 r-xp 00000000 08:03 331754 /lib/i686/cmov/libm-2.11.2.so b75f8000-b75f9000 r--p 00023000 08:03 331754 /lib/i686/cmov/libm-2.11.2.so b75f9000-b75fa000 rw-p 00024000 08:03 331754 /lib/i686/cmov/libm-2.11.2.so b75fa000-b76e3000 r-xp 00000000 08:03 14850 /usr/lib/libstdc++.so.6.0.13 b76e3000-b76e7000 r--p 000e9000 08:03 14850 /usr/lib/libstdc++.so.6.0.13 b76e7000-b76e8000 rw-p 000ed000 08:03 14850 /usr/lib/libstdc++.so.6.0.13 b76e8000-b76ef000 rw-p 00000000 00:00 0 b770a000-b770d000 rw-p 00000000 00:00 0 b770d000-b770e000 r-xp 00000000 00:00 0 [vdso] b770e000-b7729000 r-xp 00000000 08:03 331489 /lib/ld-2.11.2.so b7729000-b772a000 r--p 0001a000 08:03 331489 /lib/ld-2.11.2.so b772a000-b772b000 rw-p 0001b000 08:03 331489 /lib/ld-2.11.2.so bff0a000-bff1f000 rw-p 00000000 00:00 0 [stack] Abort
je ne sait c'est due à quoi , aucune erreur de complilation , il exécute bien et au moment de détruire sa plante ! ...
merci d'avance
Partager