File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -482,7 +482,7 @@ struct FilterInputerAdapter {
482
482
483
483
``` cpp
484
484
struct FilterStrategy {
485
- virtual bool shouldDrop (int value) = 0; // 返回 true 表示该值应该被丢弃
485
+ virtual bool shouldPass (int value) = 0; // 返回 true 表示该值应该被保留
486
486
};
487
487
488
488
struct FilterStrategyAbove : FilterStrategy { // 大于一定值(threshold)才能通过
@@ -732,7 +732,6 @@ void player(Gun *gun) {
732
732
733
733
player(new GunWithBullet<AK47Bullet >());
734
734
player(new GunWithBullet<MagicBullet >());
735
- };
736
735
```
737
736
738
737
这样就不必每次添加新子弹类型时,都得新建一个相应的枪类型了,进一步避免了代码重复。可见模板元编程完全可与传统面向对象强强联手。
@@ -1068,7 +1067,7 @@ struct Sprite {
1068
1067
virtual void draw(glm::vec3 position) = 0;
1069
1068
};
1070
1069
1071
- struct FireSprite {
1070
+ struct FireSprite : Sprite {
1072
1071
vector<char > fireTexture;
1073
1072
1074
1073
FireSprite() : fireTexture(loadTexture("fire.jpg")) {}
@@ -1078,7 +1077,7 @@ struct FireSprite {
1078
1077
}
1079
1078
};
1080
1079
1081
- struct IceSprite { // 假如寒冰弹需要两张贴图,也没问题!因为虚接口类允许子类有不同的成员,不同的结构体大小
1080
+ struct IceSprite : Sprite { // 假如寒冰弹需要两张贴图,也没问题!因为虚接口类允许子类有不同的成员,不同的结构体大小
1082
1081
vector<char > iceTexture1;
1083
1082
vector<char > iceTexture2;
1084
1083
You can’t perform that action at this time.
0 commit comments