我是新手,对C++不太熟悉。因此,我尝试编写一个非常简单的控制台应用程序,用以填充2D数组并显示其内容。
但是,我编写的代码无法编译。
其中一些错误如下:
error C2065: 'box' : 未声明的标识符
error C2228: '.GenerateBox' 的左侧必须有类/结构/联合体
以下是我的代码:
#include <iostream>
using namespace std;
int main()
{
Box box;
box.GenerateBox();
}
class Box
{
private:
static int const maxWidth = 135;
static int const maxHeight = 60;
char arrTest[maxWidth][maxHeight];
public:
void GenerateBox()
{
for (int i=0; i<maxHeight; i++)
for (int k=0; k<maxWidth; k++)
{
arrTest[i][k] = 'x';
}
for (int i=0; i<maxHeight; i++)
{
for (int k=0; k<maxWidth; k++)
{
cout << arrTest[i][k];
}
cout << "\n";
}
}
};
有什么想法导致这些错误吗?