如何从主程序设置数组的维度?
我有 Loza 类,我想创建对象(设置容量和价格),并创建包含“容量”整数的字段。但是当我想在字段中设置另一个数字时: aray[i] = 1;
编译器会说:
invalid conversion from `int' to `int*' in array
我该如何解决这个问题?我只想将字段索引上的元素设置为另一个数字(0/1)
class Loza {
public:
Loza(int capacity, int price) {
this->capacity = capacity;
this->price = price;
*aray = new int[capacity];
for (int i = 0; i < capacity; i++) {
aray[i] = 0;
}
}
virtual ~Loza();
void info();
bool set(int i) {
if (aray[i] == 0) {
aray[i] = 1;
return true;
} else {
return false;
}
}
int getCapacity() const {
return capacity;
}
int getPrice() const {
return price;
}
void setCapacity(int pocetMiest) {
this->capacity = pocetMiest;
}
void setPrice(int cenaMiesta) {
this->price = cenaMiesta;
}
private:
int capacity;
int price;
int *aray[];
};