-2

i dont know how to initzalitze a 3d matrix.

Thats the 3d matrix of terminal class:

contenidor ***_terminal;

Thats the hpp of contenidor class:

class contenidor {

public:

  contenidor(const string &m, nat l) throw(error);

  contenidor(const contenidor &u) throw(error);

  ~contenidor() throw();

private:

   string _m;

   nat _l;

Thats how i try to initialize:

contenidor _terminal = new contenidor**[n];
for(int x = 0; x < n; ++x) {
  _terminal[x] = new contenidor*[m];
  for(int y = 0; y < m; ++y) {
    _terminal[x][y] = new contenidor[y];
    for(int z = 0; z < h; ++z) { 
      _terminal[x][y][z] = 0;
    }
  }
}

Errors displayeds from terminal:

terminal.cpp: In constructor ‘terminal::terminal(util::nat, util::nat, util::nat, terminal::estrategia)’:
terminal.cpp:33:43: error: no matching function for call to ‘contenidor::contenidor()’
         _terminal[x][y] = new contenidor[y];
                                           ^
terminal.cpp:33:43: note: candidates are:
In file included from terminal.hpp:9:0,
                 from terminal.cpp:1:
contenidor.hpp:16:3: note: contenidor::contenidor(const contenidor&)
   contenidor(const contenidor &u) throw(error);
   ^
contenidor.hpp:16:3: note:   candidate expects 1 argument, 0 provided
contenidor.hpp:14:3: note: contenidor::contenidor(const string&, util::nat)
   contenidor(const string &m, nat l) throw(error);
   ^
contenidor.hpp:14:3: note:   candidate expects 2 arguments, 0 provided
terminal.cpp:35:8: error: ‘array’ was not declared in this scope
        array[x][y][z] = 0;
        ^
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
Albert
  • 1
  • 1
    possible duplicate of [c++ Object array initialization without default constructor](http://stackoverflow.com/questions/4754763/c-object-array-initialization-without-default-constructor) – BDL Jan 02 '15 at 13:16
  • i have a instructions to devolop all calsses and i cant use de default constructor, only the 2 constructors i have show. – Albert Jan 02 '15 at 16:22

2 Answers2

0

Believe the problem lies here; your two constructors are:

contenidor(const string &m, nat l) throw(error);
contenidor(const contenidor &u) throw(error);

But you are calling _terminal[x][y] = new contenidor[y]; which is trying to find an no-args constructor, contenidor(). Either create a constructor that takes no args, or pass args to the _terminal[x][y] = new contenidor(...some arguments here...)[y];.

tendim
  • 447
  • 3
  • 10
0

The problem is that i have a no modificable hpp, and i cant add no-args constructor, the answered sintax: _terminal[x][y] = new contenidor(...some arguments here...)[y]; is not correct

Can someone give me a complet and correct solution please?.

Thanks.

Albert
  • 1