首页 新闻 会员 周边

C++多文件编译 结构体未定义错误

0
悬赏园豆:20 [已关闭问题] 关闭于 2018-06-03 11:42

在一个项目中,有许多类分别定义在各自的头文件中,包括结构体,然而在使用过程中发现,在一个头文件中定义的结构体在另一个头文件的结构体声明中作为已存在类型声明成员变量时,编译无法通过,提示该类型未定义。

具体如下:

 1 #include "Leaps.h"
 2 #include "Guards.h"
 3 
 4 class CGuards;
 5 class CLeaps;
 6 struct leapRecords;
 7 
 8 struct personnel
 9 {    
10     int cbsize;
11     char name[255];
12     //0=none;1=once;2=leaps
13     int leapOpt;
14     leapRecords leaps;
15 };
16 
17 //以上代码为核心问题代码,其余代码未贴上,如有需要我在附上

问题就出在leapRecords这个结构体成员类型上了,它定义在"Leaps.h",下面附上代码:

 1 #ifndef LEAPS_H
 2 #define LEAPS_H
 3 
 4 #include "Guard.h"
 5 #include "Leap.h"
 6 #include <vector>
 7 using std::vector;
 8 
 9 class CGuard;
10 struct leapRecord;
11 
12 struct leapRecords
13 {
14     //标识输出到文件的大小而非对齐后大小
15     int cbsize;
16     leapRecord *records;
17 };
18 
19 class CLeaps
20 {
21 public:
22     CLeaps():leaps(0)
23     {
24         parent=nullptr;
25         now=&leaps.at(0);
26         records.cbsize=0;
27         records.records=nullptr;
28     }
29 
30     ~CLeaps(void);
31 
32     //请求跳岗记录集
33     leapRecords enquireRecords();
34     //销毁传输使用的记录集
35     void destroyRecords();
36 
37     //自定义迭代器
38     typedef CLeap* iterator;
39 
40     void append(CLeap& leap);
41     void remove(const CLeap& leap);
42     void clear(void);
43 
44     int size()const;
45 
46     iterator begin();
47     iterator end();
48 
49     CLeap& operator[](int selector);
50 
51     iterator operator++();
52     iterator operator++(int);
53     iterator operator--();
54     iterator operator--(int);
55     CLeap& operator*();
56     bool operator==(iterator& ite);
57     bool operator!=(iterator& ite);
58 
59     CGuard* linkToGuard(CGuard* gurd);
60 
61 private:
62 
63     CGuard *parent;
64     //CLeap组
65     vector<CLeap> leaps;
66     //支持迭代器,标记当前位置
67     iterator now;
68     //用来输出跳岗记录集
69     leapRecords records;
70 };
71 
72 #endif

以防疏漏,上面这个头文件我是完整复制过来的,重点只在类外结构体的定义上。

从逻辑角度找不出问题啊,可是就是编译无法通过,错误如下:

就是提示未定义,我也是头大了。

小弟C++编程,尤其是多文件编译没有经验,也不知道哪里的问题,应该不是依赖项的问题吧。

请大神指教!!!

问题补充:

跪求大神,时间有限,有没有大神耐心剖析一下,感激不尽。。。。

TearsOfDawn的主页 TearsOfDawn | 初学一级 | 园豆:34
提问于:2018-06-03 10:01
< >
分享
所有回答(1)
0

遍览各大网站,看到终于找到思路。

还是依赖项出现的问题。

关于依赖项的较为准确说法链接点击

头文件互相包含是大忌,会导致依赖项问题,新手注意!

TearsOfDawn | 园豆:34 (初学一级) | 2018-06-03 11:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册