回答編集履歴
1
追記
test
CHANGED
@@ -91,3 +91,129 @@
|
|
91
91
|
}
|
92
92
|
|
93
93
|
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
[追記] ぢゃ...コレじゃダメっすか?
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
```C++
|
102
|
+
|
103
|
+
#include <iostream>
|
104
|
+
|
105
|
+
#include <vector>
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
class appUpdate;
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
struct ParamClass {
|
114
|
+
|
115
|
+
// 関数ポインタ
|
116
|
+
|
117
|
+
typedef void (appUpdate::* LPFN_FUNC)(void);
|
118
|
+
|
119
|
+
LPFN_FUNC m_pFunc;
|
120
|
+
|
121
|
+
// レシーバ
|
122
|
+
|
123
|
+
appUpdate* m_pReceiver;
|
124
|
+
|
125
|
+
ParamClass(appUpdate* recv, LPFN_FUNC func) : m_pReceiver(recv), m_pFunc(func) {}
|
126
|
+
|
127
|
+
void execute();
|
128
|
+
|
129
|
+
};
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
class appManager {
|
134
|
+
|
135
|
+
public:
|
136
|
+
|
137
|
+
appManager() {}
|
138
|
+
|
139
|
+
~appManager() {}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
private:
|
144
|
+
|
145
|
+
std::vector<ParamClass> m_ParamList;
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
public:
|
150
|
+
|
151
|
+
// m_pFuncに登録された関数をコールする関数
|
152
|
+
|
153
|
+
void ExecFunc(void) {
|
154
|
+
|
155
|
+
for ( auto& param : m_ParamList ) param.execute();
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
// 関数の登録処理
|
162
|
+
|
163
|
+
void EntryFunc(ParamClass param) {
|
164
|
+
|
165
|
+
m_ParamList.emplace_back(param);
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
};
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
class appUpdate {
|
174
|
+
|
175
|
+
public:
|
176
|
+
|
177
|
+
appUpdate() {}
|
178
|
+
|
179
|
+
~appUpdate() {}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
public:
|
184
|
+
|
185
|
+
// appManagerのParamClassに登録する関数
|
186
|
+
|
187
|
+
void UpdateRender() { std::cout << "appUpdate::UpdateRender()\n"; }
|
188
|
+
|
189
|
+
};
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
void ParamClass::execute() { (m_pReceiver->*m_pFunc)(); }
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
int main() {
|
198
|
+
|
199
|
+
appManager mngr;
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
appUpdate app1;
|
204
|
+
|
205
|
+
appUpdate app2;
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
mngr.EntryFunc(ParamClass(&app1, &appUpdate::UpdateRender));
|
210
|
+
|
211
|
+
mngr.EntryFunc(ParamClass(&app2, &appUpdate::UpdateRender));
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
mngr.ExecFunc();
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
```
|