File tree 1 file changed +20
-2
lines changed
1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ All of the three classes support function removal by using '-='
23
23
action -= foo;
24
24
action.Invoke();
25
25
26
- Prints: Nothing.
26
+ // Prints: Nothing.
27
27
```
28
28
29
29
### Func
@@ -40,7 +40,7 @@ func.Invoke(5, 'A');
40
40
```
41
41
42
42
### Delegate
43
- His purpose is to store functions whose return type is not void with 0 or more parameters.
43
+ His purpose is to store functions whose return type could be whatever, with 0 or more parameters.
44
44
45
45
``` C++
46
46
Delegate<int()> delegate;
@@ -56,6 +56,17 @@ for (const auto &item : delegate.Invoke()) std::cout << item;
56
56
// Prints: 123
57
57
```
58
58
59
+ As with _ Funcs_ , you can also pass parameters to the Invoke method.
60
+ ``` C++
61
+ int square (int x) { return x * x; }
62
+
63
+ Delegate<int(int)> delegate;
64
+ delegate += square;
65
+
66
+ std::cout << delegate.Invoke(2)[ 0] ;
67
+ // Prints: 4
68
+ ```
69
+
59
70
## Frequent questions
60
71
### Can I add member functions?
61
72
Yes! Perhaps is not in the most beautiful way, but still does the trick. You just need to use lambdas like this.
@@ -74,3 +85,10 @@ action.Invoke();
74
85
// Prints: 5A6B
75
86
```
76
87
88
+ ### Something else you didn't mention?
89
+ Thanks for asking. The operator `+=` is overloaded to accept a vector.
90
+ ``` C++
91
+ delegate += { foo, bar };
92
+ ```
93
+ You can also reset or clear the delegate with ` delegate.Clear() `
94
+
You can’t perform that action at this time.
0 commit comments