Arrêt inattendu du programme
Bonjour,
Le programme dont les sources sont ci-dessous s'arrête de façon inattendue, mais je n'arrive pas à comprendre pourquoi.
Code:
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
| #include <iostream>
#include <vector>
#include "B.hpp"
#include "A.hpp"
using namespace std;
int main(){
vector<A> listeDeA;
int nbA=10;
// We create the agents
for(int i=0;i<nbA;i++){
cout << "-------- Creation of the A number " << i << "/" << nbA-1 << " --------" << endl;
A a;
cout << "1" << endl;
listeDeA.push_back(a);
cout << "2" << endl << endl;
}
cout << "OK" << endl;
return EXIT_SUCCESS;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #ifndef _A_HPP_
#define _A_HPP_
class A{
public:
B* b;
//////////
A();
~A();
};
#endif |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #include <iostream>
#include "B.hpp"
#include "A.hpp"
using namespace std;
A::A(){
cout << "In the A constructor" << endl;
b=new B();
}
A::~A(){
cout << "In the A destructor" << endl;
if(b!=NULL){
delete b;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #ifndef _B_HPP_
#define _B_HPP_
class B{
private:
int *n1;
float **n2;
float **n3;
float ***n4;
public:
B();
~B();
};
#endif |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #include <iostream>
#include "B.hpp"
using namespace std;
B::B(){
cout << "In the B constructor (" << this << ")" << endl;
}
B::~B(){
cout << "In the B destructor (" << this << ")" << endl;
} |
Lorsque je lance le programme, il s'arrête à la 7e itération du for de main.cpp.
Le code retourné est -1073741819.
Merci de votre aide !