小编ste*_*ken的帖子

C:"无效使用未定义类型'struct X'并取消引用指向不完整类型的指针"错误

我一直在和我的类似问题仔细研究几天,但仍未找到解决方案.谢谢任何帮助:

我有两个文件,一个包含处理有理数的方法,另一个在二维数组中处理它们.我的问题是matrix.c不能识别fraction.c中包含的分数结构.我相信我的问题与我宣布我的2d数组的方式有某种关系.

在fraction.c中:

struct fraction {
   int integer;
   int num;
   int den;
};
typedef struct fraction* fractionRef;  //This line is in fraction.h
Run Code Online (Sandbox Code Playgroud)

在matrix.c中:

#include "fraction.h"

typedef struct matrix* matrixRef;

struct matrix {
   int rows;
   int columns;
   fractionRef *m;
}matrix;

matrixRef new_matrix ( int rows, int columns ) {
   matrixRef matrix;
   matrix = (matrixRef)malloc( sizeof( matrix ) );
   matrix->m = (fractionRef*)calloc( rows, sizeof( fractionRef ) );
   int i;
   for ( i=0; i<=rows; i++ )
     matrix->m[i] = (fractionRef)calloc( columns, sizeof( fractionRef ) …
Run Code Online (Sandbox Code Playgroud)

c compiler-errors multidimensional-array

6
推荐指数
2
解决办法
2万
查看次数