@@ -14,15 +14,15 @@ namespace SimpleExample
14
14
{
15
15
public:
16
16
virtual ~Superpower () {}
17
-
17
+
18
18
protected:
19
19
virtual void activate () = 0;
20
-
20
+
21
21
void move (double x, double y, double z)
22
22
{
23
23
// Code here...
24
24
}
25
-
25
+
26
26
void playSound (SoundId sound, double volume)
27
27
{
28
28
// Code here...
@@ -34,7 +34,7 @@ namespace SimpleExample
34
34
}
35
35
};
36
36
// ^1
37
-
37
+
38
38
// ^2
39
39
class SkyLaunch : public Superpower
40
40
{
@@ -69,15 +69,15 @@ namespace Elaborated
69
69
return 0 ;
70
70
// ^omit
71
71
}
72
-
72
+
73
73
double getHeroY ()
74
74
{
75
75
// Code here...
76
76
// ^omit
77
77
return 0 ;
78
78
// ^omit
79
79
}
80
-
80
+
81
81
double getHeroZ ()
82
82
{
83
83
// Code here...
@@ -89,7 +89,7 @@ namespace Elaborated
89
89
// Existing stuff...
90
90
};
91
91
// ^3
92
-
92
+
93
93
// ^4
94
94
class SkyLaunch : public Superpower
95
95
{
@@ -107,7 +107,7 @@ namespace Elaborated
107
107
{
108
108
// Near the ground, so do a double jump.
109
109
playSound (SOUND_SWOOP, 1 .0f );
110
- move (0 , 0 , getHeroZ () - 20 );
110
+ move (0 , 0 , getHeroZ () + 20 );
111
111
}
112
112
else
113
113
{
@@ -127,9 +127,9 @@ namespace Forwarding
127
127
{
128
128
void play (SoundId sound, double volume) {}
129
129
};
130
-
130
+
131
131
SoundEngine soundEngine_;
132
-
132
+
133
133
// ^5
134
134
void playSound (SoundId sound, double volume)
135
135
{
@@ -153,12 +153,12 @@ namespace HelperClassBefore
153
153
{
154
154
// Code here...
155
155
}
156
-
156
+
157
157
void setVolume (SoundId sound)
158
158
{
159
159
// Code here...
160
160
}
161
-
161
+
162
162
// Sandbox method and other operations...
163
163
};
164
164
// ^6
@@ -173,19 +173,19 @@ namespace HelperClassAfter
173
173
{
174
174
// Code here...
175
175
}
176
-
176
+
177
177
void stopSound (SoundId sound)
178
178
{
179
179
// Code here...
180
180
}
181
-
181
+
182
182
void setVolume (SoundId sound)
183
183
{
184
184
// Code here...
185
185
}
186
186
};
187
187
// ^7
188
-
188
+
189
189
// ^8
190
190
class Superpower
191
191
{
@@ -194,9 +194,9 @@ namespace HelperClassAfter
194
194
{
195
195
return soundPlayer_;
196
196
}
197
-
197
+
198
198
// Sandbox method and other operations...
199
-
199
+
200
200
private:
201
201
SoundPlayer soundPlayer_;
202
202
};
@@ -206,19 +206,19 @@ namespace HelperClassAfter
206
206
namespace PassToConstructor
207
207
{
208
208
class ParticleSystem {};
209
-
209
+
210
210
// ^pass-to-ctor-base
211
211
class Superpower
212
212
{
213
213
public:
214
214
Superpower (ParticleSystem* particles)
215
215
: particles_(particles)
216
216
{}
217
-
217
+
218
218
// Sandbox method and other operations...
219
-
219
+
220
220
private:
221
- ParticleSystem* particles_;
221
+ ParticleSystem* particles_;
222
222
};
223
223
// ^pass-to-ctor-base
224
224
@@ -236,15 +236,15 @@ namespace PassToConstructor
236
236
namespace TwoStageInit
237
237
{
238
238
class ParticleSystem {};
239
-
239
+
240
240
class Superpower
241
241
{
242
242
public:
243
243
void init (ParticleSystem* particles) {}
244
244
};
245
-
245
+
246
246
ParticleSystem* particles;
247
-
247
+
248
248
class SkyLaunch : public Superpower {};
249
249
250
250
void foo ()
@@ -259,15 +259,15 @@ namespace TwoStageInit
259
259
namespace TwoStageInitEncapsulated
260
260
{
261
261
class ParticleSystem {};
262
-
262
+
263
263
class Superpower
264
264
{
265
265
public:
266
266
void init (ParticleSystem* audio) {}
267
267
};
268
-
268
+
269
269
class SkyLaunch : public Superpower {};
270
-
270
+
271
271
// ^10
272
272
Superpower* createSkyLaunch (ParticleSystem* particles)
273
273
{
@@ -281,7 +281,7 @@ namespace TwoStageInitEncapsulated
281
281
namespace StaticState
282
282
{
283
283
class ParticleSystem {};
284
-
284
+
285
285
// ^11
286
286
class Superpower
287
287
{
@@ -290,7 +290,7 @@ namespace StaticState
290
290
{
291
291
particles_ = particles;
292
292
}
293
-
293
+
294
294
// Sandbox method and other operations...
295
295
296
296
private:
@@ -305,15 +305,15 @@ namespace UseServiceLocator
305
305
{
306
306
void spawn (ParticleType type, int count);
307
307
};
308
-
308
+
309
309
ParticleSystem particles;
310
-
310
+
311
311
class Locator
312
312
{
313
313
public:
314
314
static ParticleSystem& getParticles () { return particles; }
315
315
};
316
-
316
+
317
317
// ^12
318
318
class Superpower
319
319
{
@@ -323,7 +323,7 @@ namespace UseServiceLocator
323
323
ParticleSystem& particles = Locator::getParticles ();
324
324
particles.spawn (type, count);
325
325
}
326
-
326
+
327
327
// Sandbox method and other operations...
328
328
};
329
329
// ^12
0 commit comments