【发布时间】:2016-11-02 17:41:24
【问题描述】:
我正在尝试用 C 解决康威的生命游戏。我编写了一个包含我所有函数的 .h 文件,但我在头文件中收到以下错误: 错误:未知类型名称“矩阵”
这是头文件的开头,其中包含我的结构声明和第一个函数:
#include<stdio.h>
#include<string.h>
#define MAX 1000
struct matrix{
int Val, Next;
};
void intro_date(int nr_elem, matrix a[MAX][MAX]){
int x,y;
printf("Enter the line and the column of the element which you wish to read within the matrix: \n");
while(nr_elem){
scanf("%d%d",&x,&y);
a[x][y].Val=1;
--nr_elem;
}
}
【问题讨论】:
-
在 C 中不能省略
struct关键字,matrix a[MAX][MAX]应该是struct matrix a[MAX][MAX](或使用typedef) -
或者定义应该是
typedef struct matrix{ int Val, Next; } matrix;。 -
你不应该把函数实现放在 C 头文件中,只放在它们的原型中。包括实现也容易产生重复的定义,这是不允许的。
标签: c