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 {
482482
483483``` cpp
484484struct FilterStrategy {
485- virtual bool shouldDrop (int value) = 0; // 返回 true 表示该值应该被丢弃
485+ virtual bool shouldPass (int value) = 0; // 返回 true 表示该值应该被保留
486486};
487487
488488struct FilterStrategyAbove : FilterStrategy { // 大于一定值(threshold)才能通过
@@ -725,7 +725,6 @@ void player(Gun *gun) {
725725
726726player(new GunWithBullet<AK47Bullet >());
727727player(new GunWithBullet<MagicBullet >());
728- };
729728```
730729
731730这样就不必每次添加新子弹类型时,都得新建一个相应的枪类型了,进一步避免了代码重复。可见模板元编程完全可与传统面向对象强强联手。
@@ -1061,7 +1060,7 @@ struct Sprite {
10611060 virtual void draw(glm::vec3 position) = 0;
10621061};
10631062
1064- struct FireSprite {
1063+ struct FireSprite : Sprite {
10651064 vector<char > fireTexture;
10661065
10671066 FireSprite() : fireTexture(loadTexture("fire.jpg")) {}
@@ -1071,7 +1070,7 @@ struct FireSprite {
10711070 }
10721071};
10731072
1074- struct IceSprite { // 假如寒冰弹需要两张贴图,也没问题!因为虚接口类允许子类有不同的成员,不同的结构体大小
1073+ struct IceSprite : Sprite { // 假如寒冰弹需要两张贴图,也没问题!因为虚接口类允许子类有不同的成员,不同的结构体大小
10751074 vector<char > iceTexture1;
10761075 vector<char > iceTexture2;
10771076
You can’t perform that action at this time.
0 commit comments