大佬教程收集整理的这篇文章主要介绍了C 头文件中的未知类型名称,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在编译项目时遇到问题。我正在尝试将一个结构体放入一个队列中,该结构体在头文件中是这样的:
预约函数头文件(“signupFunctions.h”是我的“患者”声明的地方):
String = ((TextVIEw) findVIEwByID(R.ID.signup_email)).getText().toString();
队列函数头文件:
#ifndef appointmentFunctions_H__
#define appointmentFunctions_H__
#include "queueFunctions.h"
#include "signupFunctions.h"
typedef struct{
int cough;
int rdistress;
int fatigue;
int fever;
}symptoms;
typedef symptoms *Symptoms;
typedef struct {
PatIEnt patIEnt;
Symptoms symptoms;
int day;
int mon;
int year;
int flag;
}appointment;
typedef appointment *Appointment;
int getSymptomsValue(Appointment A);
voID setSymptoms(Appointment A);
voID requestAppointment(PatIEnt P,qNodePtr *head,qNodePtr *tail);
#endif
一旦我编译我得到:
#ifndef queueFunctions_H__
#define queueFunctions_H__
#include "appointmentFunctions.h"
typedef struct qNode{
Appointment A;
struct qNode *next;
}QueueNode;
typedef QueueNode *qNodePtr;
voID printQueue(qNodePtr currentPtr);
int isEmpty(qNodePtr head);
voID dequeue(qNodePtr *head,qNodePtr *tail);
voID enqueue(qNodePtr *head,qNodePtr *tail,Appointment App);
#endif
..等等。有什么问题?提前致谢。
在appointmentFunctions.h 中包含queueFunctions.h
因此,当读取 queueFunctions.h 时,类型 Appointment
是未知的。
queueFunctions.h 也包含了appointmentFunctions.h 对你没有帮助,因为那时已经定义了appointmentFunctions_H__,即不会读取文件内容。
如果文件 X.h 依赖于文件 Y.h 中的某些内容,同时 Y.h 依赖于文件 X.h 中的某些内容,则您有一个必须修复的设计错误。
据我所知,依赖只是指向结构的指针,因此您可以通过向前声明结构来摆脱依赖。
#include "appointmentFunctions.h" --> struct appointment;
Appointment --> struct appointment*
顺便说一句:这是基于意见的,但大多数程序员避免使用 typedef 来表示指针。如果完成,通常最好使用一个明确表明这是一个指针的名称,例如:
typedef appointment *Appointment; --> typedef appointment *appointmentPtr;
,
您递归地将一个标题包含在另一个标题中
#ifndef appointmentFunctions_H__
#define appointmentFunctions_H__
#include "queueFunctions.h"
#include "signupFunctions.h"
//...
和
#ifndef queueFunctions_H__
#define queueFunctions_H__
#include "appointmentFunctions.h"
//...
所以编译器会报错。
你不能那样做。
即标头 appointmentFunctions.h
一次包含标头 queueFunctions.h
,其中有声明
typedef struct qNode{
Appointment A;
struct qNode *next;
}QueueNode;
以上是大佬教程为你收集整理的C 头文件中的未知类型名称全部内容,希望文章能够帮你解决C 头文件中的未知类型名称所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。