我想要創建一個結構數組,但我得到錯誤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