我在这个程序中的2个不同的地方得到了相同的错误,它应该会产生1d,2d和3d数组并存储值并同时显示它们。 错误:下标要求数组或指针类型/表达必须有指针到对象类型 误差是用于表达C [R] [C] [深度]这个数组程序有什么问题?
#include<iostream>
using namespace std;
#define ROW 5
#define COL 5
#define DEPTH 5
int main()
{
int *a; // 1d array
a=new int [COL];
int (*b) [COL]; //2d array
b=new int [ROW][COL];
int (*c)[ROW][COL];
c=new int [ROW][COL][DEPTH]; // 3d array
//---------------------------------------------------------------------------------
// storing values in the arrays:
for(int i=0;i<COL;i++)
{
a[i]=i+2;
cout << a[i];
}
// 2d array
for(int r=0;r<ROW;r++)
{
for(int c=0;c<COL;c++)
{
b[r][c]=r+c+2;
cout << b[r][c];
}
}
// 3d array
for(int r=0;r<ROW;r++)
{
for(int c=0;c<COL;c++)
{
for(int depth=0;depth<DEPTH;depth++)
{
c[r][c][depth]=r+c+depth+2; //error
cout << c[r][c][depth]; //same error
}
}
}
//-------------------------------------------------------------------------------------
}