在声明.h文件中一个结构和.c文件执行 [英] declaring a struct in .h file and implementing in .c file
本文介绍了在声明.h文件中一个结构和.c文件执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的.h文件中:
struct _MyString;
typedef struct _MyString MyString;
我想在.c文件及其成员申报。
i would like to declare its members in the .c file.
我尝试:
typedef struct MyString{
char * _str;// pointer to the matrix
unsigned long _strLength;
}MyString;
,但它不工作。
我如何声明结构的承包商,客人在.c文件?
but it doesn't work. how do i declare the struct's memebers in the .c file?
感谢您
推荐答案
您只需要1的typedef。保持一个你已经有了.h文件,并删除所有其他人。
You need only 1 typedef. Keep the one you already have in the .h file and delete all others.
现在,该结构名为结构_MyString
。这是你应该在.c文件中定义的,而不是结构MyString中
:注意到缺少的'_'
Now, the struct name is struct _MyString
. That is what you should define in the .c file, not struct MyString
: notice the absence of the '_'.
所以
.h文件中
struct _MyString;
typedef struct _MyString MyString;
.c文件
#include "file.h"
struct _MyString {
char * _str;// pointer to the matrix
unsigned long _strLength;
};
这篇关于在声明.h文件中一个结构和.c文件执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文