Skip to content

Commit a7d4e7a

Browse files
committed
Rename example functions to avoid "foo"-like constructs
1 parent 0ba84b7 commit a7d4e7a

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

docs/reference/api/platform/Callback.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,19 @@ Here is an example that uses everything discussed in the [introduction to callba
2828
Callbacks overload the function call operator, so you can call a Callback like you would a normal function:
2929

3030
```c++
31-
void callme(Callback<void(float)> cb) {
32-
cb(1.0f);
31+
void run_timer_event(Callback<void(float)> on_timer) {
32+
on_timer(1.0f);
3333
}
3434
```
3535
3636
The only thing to watch out for is that the Callback type has a null Callback, just like a null function pointer. Uninitialized callbacks are null and assert if you call them. If you want a call to always succeed, you need to check if it is null first.
3737
3838
``` c++
39-
void callmemaybe(Callback<void(float)> cb) {
40-
if (cb) {
41-
cb(1.0f);
39+
void run_timer_event(Callback<void(float)> on_timer) {
40+
if (on_timer) {
41+
on_timer(1.0f);
4242
}
4343
}
4444
```
4545

4646
The Callback class is what’s known in C++ as a “Concrete Type”. That is, the Callback class is lightweight enough to be passed around like an int, pointer or other primitive type.
47-
48-
```c++
49-
class Thing {
50-
private:
51-
Callback<void(int)> _cb;
52-
53-
public:
54-
void attach(Callback<void(int)> cb) {
55-
_cb = cb
56-
}
57-
58-
void dothething(int arg) {
59-
If (_cb) {
60-
_cb(arg);
61-
}
62-
}
63-
}
64-
```
65-

0 commit comments

Comments
 (0)