我想要创建一个结构数组,但我得到错误no matching function for call to 'Cell::Cell()'
。创建一个结构数组
Cell
是我的结构的名称。这里是我的一些代码:
struct Cell{
int number;
Cell(int n){
number = n;
}
};
class MyClass{
public:
int nCells;
void inject(){
std::cout << "Enter number:";
string in;
std::cin >> in;
int amount = in.size()/3;
Cell cells [amount]; // <-- error
int index = 0;
int t = in.size();
while (t >= 3){
cells[index] = new Cell(atoi(in.substr(t-3,3).c_str());
t -= 3;
index++;
}
}
MyClass(int n){
nCells = n;
}
};
Cell cells [amount];
给我的错误。我对类很陌生,但我知道如何创建基本类型的数组。例如,int cells [amount];
就可以工作。
但我该如何制作一个Cell
类型的数组?
使用std ::矢量 – Davidbrcz
哪里是默认的构造函数中的细胞?你没有它。 – Jepessen