【发布时间】:2015-01-02 13:11:05
【问题描述】:
我不知道如何初始化 3d 矩阵。
这就是终端类的3d矩阵:
contenidor ***_terminal;
这就是contenidor类的hpp:
class contenidor {
public:
contenidor(const string &m, nat l) throw(error);
contenidor(const contenidor &u) throw(error);
~contenidor() throw();
private:
string _m;
nat _l;
这就是我尝试初始化的方式:
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;
}
}
}
终端显示的错误:
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;
^
【问题讨论】:
-
我有一个指令来开发所有的类,我不能使用默认构造函数,只有我显示的 2 个构造函数。
标签: c++ arrays dynamic matrix 3d