【发布时间】:2016-05-03 10:27:54
【问题描述】:
现在我正在为我的系统编程课程做一个项目。我们被要求与房地产经纪人和客户一起设计一个公寓销售平台。我正在开发 Eclipse。
现在,即使我过去没有遇到任何类似的问题,但我的一个头文件无法从第二个头文件中识别 typedef。
说明:这是我的文件;
房地产经纪人.h
#include "apartment.h"
#include "apartment_service.h"
#include "Report.h"
#include "Customer.h"
#include "mtm_ex2.h"
typedef struct realtor_t* Realtor;
虽然这是第二个头文件;
客户.h
#include "Report.h"
#include "Realtor.h"
#include "apartment.h"
#include "apartment_service.h"
#include "mtm_ex2.h"
typedef struct customer_t* Customer;
MtmErrorCode purchaseApartment (Customer customer, Realtor realtor,
ApartmentService service,
int apartment_id);
MtmErrorCode makeOffer (Customer customer, Realtor realtor, ApartmentService
service, int apartment_id, int new_price);
(customer_t和realtor_t的结构体在源文件中定义)
出于某种原因,Customer.h 中的函数声明给了我以下错误:“未知类型名称'Realtor'”。这真的很奇怪,因为相同的函数使用其他类型定义,例如“apartment_service.h”中的“ApartmentService”。
【问题讨论】:
-
我缺少一些包含保护,因为您的标题中有循环包含。你有这些守卫,只是为了解决这些第一个错误。
-
补充一点:即使有警卫,
Customer.h也包括Realtor.h,其中包括Customer.h,其中包括(可能有警卫)Realtor.h。如果没有包括警卫,这根本不起作用。使用 include 守卫,Realtor.h的第二个 include 刚刚通过,您最终在Customer.h没有任何Realtor.h声明(因为您实际上正在处理该 include)。