//list.h file
typedef struct _lnode{
struct _lnode *next;
size_t row;
size_t column;
short data;
}lnode;
typedef struct _llist{
struct _lnode *head;
size_t size;
}llist;
//matrix.h file
typedef struct _matrix{
size_t width;
size_t height;
size_t k;
int **data;
}matrix;
//smatrix.h file
#include "list.h"
#include "matrix.h"
typedef struct _smatrix{
size_t width;
size_t height;
size_t k;
llist data;
}smatrix;
smatrix* make_smatrix(matrix *m);
Run Code Online (Sandbox Code Playgroud)
smatrix.h文件包含list.h文件和matrix.h文件.如果我在smatrix.h文件中包含这些头文件,那么我得到
redefinition of 'lnode'. redefinition of '_llist' and redefinition of '_matrix' errors.
Run Code Online (Sandbox Code Playgroud)
如果我从smatrix.h文件中获取了那些heder文件,那么错误就会消失,但它会在函数参数中抱怨矩阵类型.我想调用list.h中定义的函数和smatrix.c文件中的matrix.h文件.我该怎么办?提前致谢..
M'v*_*'vy 19
多重夹杂物可能存在的问题.
尝试使用保护您的头文件
文件列表
#ifndef _LISTH_
#define _LISTH_
<your code>
#endif
Run Code Online (Sandbox Code Playgroud)
file matrix.h
#ifndef _MATRIXH_
#define _MATRIXH_
<your code>
#endif
Run Code Online (Sandbox Code Playgroud)
如果你在标题包含中有一个循环,它将阻止你也有重新定义.