Problem creating 2 objects of same class

Program crashes when i create 2 objects of "imagen" class, it works with 1 object, here is the code:

MAIN.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <tr1/array>

#include "Imagen.hpp"

using namespace std;
using namespace Jose;

int main() {
   imagen prueba,aux; 
   bool ok;

   prueba.leer("a1.ppm",ok);
   system ("pause");
}



IMAGEN.HPP
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
#ifndef _Imagen_hpp_
#define _Imagen_hpp_
#include <string>
#include <tr1/array>
#include <cassert>
#include <iostream>

namespace Jose {
    class imagen {
        static const unsigned MaxTam = 500;
        struct RGB {
            short r;
            short g;
            short b;
         };
        typedef std::tr1::array <RGB, MaxTam> TFila;
        typedef std::tr1::array <TFila, MaxTam> TMatriz;
        std::string tipo;
        unsigned columnas;
        unsigned filas;
        short MaxRGB;
        TMatriz dato;
    public:
        imagen ();
        void leer (const std::string & nombrefich, bool & ok);
    };
}
#endif 


IMAGEN.CPP
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
#include <string>
#include <tr1/array>
#include <cassert>
#include <iostream>
#include <fstream>

#include "Imagen.hpp"

namespace Jose {
      imagen::imagen () {
         columnas=0;
         filas=0;
         MaxRGB=0;
         for (unsigned i=0;i<filas;i++) {
            for (unsigned j=0;i<columnas;i++) {
               dato[i][j].r=0;
               dato[i][j].g=0;
               dato[i][j].b=0;
            }
         }
      }

   void imagen::leer (const std::string & nombrefich, bool & ok) {
      std::ifstream f_ent;
      unsigned num_cuenta;
      float saldo_cuenta;
      std::string nombre_cuenta;
      f_ent.open(nombrefich.c_str());
      if (f_ent.fail()) {
         ok=false;
      } else {
         ok=true;
         f_ent>>tipo>>columnas>>filas>>MaxRGB;
         for (unsigned i=0;i<filas;i++) {
			   for (unsigned j=0;j<columnas;j++) {
			      f_ent>>dato[i][j].r;
			      f_ent>>dato[i][j].g;
			      f_ent>>dato[i][j].b;
            }
         }
         ok=!f_ent.fail();
         f_ent.close();
      }
   }

   
}


Your array (TMatriz dato) is too big to allow more than 1 imagen object to be created on the stack (the default stack size in a windows program is @ 1 megabyte).

(As a matter of fact I don't even think you can fit 1 imagen object on the stack)
Last edited on
Topic archived. No new replies allowed.