我试图制作一个充满 O 字符的矩阵,但我是新手。尝试运行时出现以下错误:
错误:“。”之前出现意外的不合格 ID 令牌。
我在课堂上做错了什么,但我不知道是什么。有人有想法吗?
#include <iostream>
using namespace std;
class field
{
private:
public:
char** the_field;
int i, j;
char** create_field(void);
void print_field();
};
////////// CREATE THE FIELD //////////
char** field::create_field(void) //define member function
{
for(int i = 0; i < 14; i++)
{
the_field[i] = new char [14];
for(int j = 0; j < 14; j++)
{
the_field[i][j] = 'O';
}
}
return the_field;
}
//////////// PRINT THE FIELD //
void field::print_field()
{
for(int i = 0; i < 14; ++i)
{
for(int j = 0; j < 14; ++j)
{
cout << " " << the_field[i][j] << " ";
}
// putchar('\n');
cout<<"\n";
}
}
int main()
{
//declare objects with type field
field create_field; //declare create_field as type of field
field print_field;
int i, j;
field.create_field();
field.print_field();
return 0;
}