.h文件中的错误重新定义 [英] Redefinition errors in .h files
问题描述
//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);
smatrix.h文件包括list.h文件和matrix.h文件。如果我包括smatrix.h文件的头文件,然后我得到
smatrix.h file includes list.h file and matrix.h files. If I include those header files in smatrix.h file then I get
redefinition of 'lnode'. redefinition of '_llist' and redefinition of '_matrix' errors.
如果我把这些文件赫德从我们的文件smatrix.h那么错误走开了,但抱怨的函数参数矩阵类型。我想打电话给在list.h和smatrix.c文件matrix.h文件中定义的函数..我该怎么办?在此先感谢..
If I took those heder files our from smatrix.h file then the error went away but it complains about matrix type in the function parameter. I want to call functions defined in list.h and matrix.h files in smatrix.c file.. What do I do? Thanks in advance..
推荐答案
多夹杂物可能出现的问题。
Possible problem of multiple inclusions.
尝试使用来保护您的头文件
Try to guard your header files with
文件list.h
#ifndef _LISTH_
#define _LISTH_
<your code>
#endif
文件matrix.h
file matrix.h
#ifndef _MATRIXH_
#define _MATRIXH_
<your code>
#endif
这将prevent你也必须重新定义,如果你有头包裹一个循环。
It will prevent you too have redefinitions if you have a loop in header inclusions.
这篇关于.h文件中的错误重新定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!