当前位置:网站首页>[Error] invalid use of incomplete type 使用了未定义的类型
[Error] invalid use of incomplete type 使用了未定义的类型
2022-06-13 00:16:00 【SZU治愈系BUG】
今天在写奥特曼打大怪兽的时候,发现一个奇怪的问题,我定义了两个基类Ultraman和Monster,一个Monster的子类Boss,然后两个基类是有相互勾结的地方,它们都或多或少的使用了对方的类型进行定义自己,然后我在第一个类实现前面进行了另一个类的声明:

之后编译报错:

然后它说不能使用不完整的类类型:
![]()
我就开始犯迷糊了,明明我两个类定义的好好的,咋就说我没有定义呢。我也在前面声明了。
然后经过我和另一个大三的学长两个人两个小时的寻找,各种排查,终于意识到一个问题:
因为这两个类是相互勾结了,所以其中一个类在使用另一个类进行对象实例化的时候,另一个类也会去找这个类对象实例化,而它们都还没有定义,简单来说就是,我需要你帮我做一件事A,但是你为了做事A需要我做事B,而我做事B必须建立在你帮我做事A的前提下。
于是找到一个解决办法:
类定义和类实现分离。
类实现写在两个类定义之后。
搞定了。
边栏推荐
- 3、 Storage system
- Tsinghua Bosch joint ml center, thbi lab:cheng Yang Ying | realize safety reinforcement learning through the value at risk of constraints
- Go custom collation
- [LeetCode]26. Removes duplicates from a sorted array thirty-three
- [LeetCode]14. Longest common prefix thirty-eight
- 2022-06-13日报: 图灵奖得主:想要在学术生涯中获得成功,需要注意哪些问题?
- Can branches sign labor contracts with employees
- 浏览器缓存的执行流程
- June 13, 2022 Daily: Turing prize winner: what should we pay attention to if we want to succeed in our academic career?
- Vscode实现PHP在浏览器实时预览
猜你喜欢

Why study PMP?

【HCIE论述】组播IGMP-A

【HCIE论述】STP-A

MASA Auth - 从用户的角度看整体设计

PLC也能制作小游戏----Codesys编写猜数字小游戏

Is the newly graduated college student taking BEC or PMP? PM who wants to transfer to another job in the future
![[hcie discussion] STP-A](/img/4f/7a76555fc7b23eafa108699f5aa5ad.png)
[hcie discussion] STP-A

How to visit a website

Day 3 of jsbom and DOM learning

Test platform series (97) perfect the case part
随机推荐
The origin of MySQL in bedtime stories
The PMP examination time in March 2022 is set -- "March 27"
Free lottery --- PMP renewal PDU | PMP knowledge map
March 11, 2022 diary: Mr. Wang's spring, strange template mode
On the usage details and special usage of switch case
C language standard IO, for example: fread(), fwrite(), fgetc(), etc. (end)
Start of u-boot S analysis (IV)
KAUST:Deyao Zhu | 价值记忆图:基于离线强化学习的图结构世界模型
[hcie discussion] rr-a
Building crud applications in golang
【Matlab】二维曲线
Why study PMP?
Delphi Chinese digit to Arabic digit
How to make maputnik, a vector tile matching artifact, support GeoServer
Accelerating with Dali modules
Go implements concurrent non blocking caching
[LeetCode]21. Merge two ordered linked lists twenty-nine
Go custom collation
How does the PMP handle the withdrawal?
安全事故等级划分为哪几级