cmake_demo/README.md
2024-09-01 16:54:38 +08:00

16 lines
731 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# cmake_demo
## CMAKE
## 多态
### 多态的本质
同样的接口,可以即实现父类的功能,也可以实现子类的功能。主要看传参的类型。
C语言实现思路
因为语法不支持,因此采用特殊的方式来实现。
| 类型 | 实现方式 | 弊端| 问题举例|
| --- | --- | --- | --- |
| 匿名结构体 | 指针 | 多重继承,成员可能冲突 | B->A, C->A, D->B,D->C|
| 虚函数表 | 指针 | 子类父类必须将虚表放在结构体最开头,且不支持多继承下的多态 | |
| 虚函数多参数 | 指针 | 继承的父类无顺序强制要求,且可以多继承。但类方法参数变多。多继承需要人为注意是调用了其他类还是继承了其他类 | |