Bonjours, je viens à vous car j'ai un core dumped et je n'arrive pas a voir ou est le problème.

je débute en C++, je suis les cours de CodeurPlusPlus sur youtube et j'ai fait exactement comme lui j'ai repris ces sources et je suis à l'dentique pour le code.

Le problème vient de l'héritage si je n'utilise pas les fonctions d'héritage donc si je fais comme ça :

ça marche, mais quand je fais :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
extintarray A=extintarray();
Là ça me fait un core dumped.
J'ai un makefile mais je penses pas que ça vienne de là.
Je suis sous cygwin version3 et j'ai essayer cygwin version4 c'est pareille.

Je vous met tout le code le test_array.cc le intarray.cc et le intarray.h

intarray.h :

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
 
#ifndef __INTARRAY_H__
#define __INTARRAY_H__
 
const int INTARRAY_DEFAULT_ALLOC = 1024;
const int INTHEAP_DEFAULT_ALLOC = 1024;
 
class intarray{
 protected: 
  int len; 
  int *data;
 public:
  intarray();
  intarray(int len);
  intarray(const intarray &A);
  ~intarray();
  int get(int index);
  void set(int index, int n);
  int length();
  friend std::ostream & operator<<(std::ostream & O,intarray & A);
};
 
class extintarray : public intarray  {
 protected: 
  int alloc;
 public:
  extintarray();
  extintarray(int alloc);
  extintarray(int len,int alloc);
  ~extintarray();
};
 
#endif
Le intarray.cc :

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
 
#include<iostream>
 
#include"intarray.h"
 
 
std::ostream &operator<<(std::ostream &O, intarray &A)
{
  for(int i=0;i<A.len;i++)
    O<<A.data[i]<<" ";
  return O;
}
 
intarray::intarray(const intarray &A)
{
  this->len=A.len;
  this->data=new int[A.len];
  for(int i=0;i<A.len;i++)
    this->data[i]=A.data[i];
}
 
int intarray::length()
{
  return this->len;
}
 
intarray::intarray()
{
  this->len=INTARRAY_DEFAULT_ALLOC;
  this->data=new int[INTARRAY_DEFAULT_ALLOC];
}
 
intarray::intarray(int len)
{
  this->len=len;
  this->data=new int[len];
}
 
intarray::~intarray()
{
  delete[] this->data;
}
 
int intarray::get(int index)
{
  return this->data[index];
}
 
void intarray::set(int index, int n)
{
  this->data[index]=n;
}
 
/**********class héritage***********************************/
 
extintarray::extintarray ()  : intarray () 
{
  this->alloc = INTARRAY_DEFAULT_ALLOC;
}
 
extintarray::extintarray (int alloc)
{
  this->len = 0;
  this->alloc = alloc;
  this->data = new int[alloc];
}
 
extintarray::extintarray (int len, int alloc)
{
  this->len = len;
  this->alloc = alloc;
  this->data = new int[alloc];
}
 
extintarray::~extintarray() 
{
  delete[] this->data;
}
Et le test_array.cc :

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
 
#include<iostream>
#include<string>
 
#include"intarray.h"
 
 
int main(int argc, std::string argv[])
{
  using namespace std;
  extintarray A=extintarray(); //marche pas. Par contre si je met : intarray A=intarray(); ça marche.
 
  /*for(int i=0;i<A.length();i++)
    {
      A.set(i,i*5);
      cout<<A.get(i)<<" ";
      }*/
  /*intarray B=intarray(A);
  cout<<A;
  cout<<endl;
  cout<<B;*/
  argc=0; argv=0;
  return 0;
}

Merci par avance pour votre aide.