非静态数据成员错误的使用无效



我正在解决一个问题,并陷入了类中的错误。

非静态数据成员'nr_piste'

的使用无效

bool harddisk [nr_piste] [nr_sectoare];

非静态数据成员的使用无效的使用'nr_sectoare'

bool harddisk [nr_piste] [nr_sectoare];

这是代码:

    class hard{
      public:
        int nr_piste, nr_sectoare, clusteri_ocupati;
        hard(){
            in >> nr_piste >> nr_sectoare >> clusteri_ocupati;
        }
        bool HardDisk[nr_piste][nr_sectoare];
        void insert(){
            int pista, sector;
            for (int i = 0; i < nr_piste; i++){
                for (int j = 0; j < nr_sectoare; j++){
                    HardDisk[i][j] = 0;
                }
            }
            for (int i = 0; i < nr_piste; i++){
                for (int j = 0; j < nr_sectoare; j++){
                    in >> pista >> sector;
                    HardDisk[pista][sector] = 1;
                }
            }
        }
    };

我尝试使用将变量放在私有的情况下,但无效。

您不能使用运行时变量来设置这样的数组尺寸。

即使可以,也可以在构造函数运行之前创建数组(成员变量(!

所以一切都是不可能的。

试试向量,以便您可以根据需要调整大小。

最新更新