<br /> <div>구현부분</div> <div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px"><div><font color="#0070c0">class </font>IFunctionPtr<br />{</div> <div><font color="#0070c0">public</font>:</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span><font color="#0070c0">virtual void </font>Func() = 0;</div> <div><br /></div> <div><font color="#0070c0">protected</font>:</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>IFunctionPtr() {}<br />};</div> <div><br /></div> <div><font color="#0070c0">template</font><<font color="#0070c0">class </font>T, <font color="#0070c0">typename </font>F></div> <div><font color="#0070c0">class </font>FunctionPtr : <font color="#0070c0">public </font>IFunctionPtr</div> <div>{</div> <div><font color="#0070c0">public</font>:</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>~FunctionPtr() {}</div> <div><br /></div> <div><span class="Apple-tab-span" style="white-space: pre"> </span><font color="#0070c0">virtual void </font>Func()<br /><span class="Apple-tab-span" style="white-space: pre"> </span>{</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>(_obj->*_func)();<br /><span class="Apple-tab-span" style="white-space: pre"> </span>}</div> <div><br /></div> <div><span class="Apple-tab-span" style="white-space: pre"> </span><font color="#0070c0">template</font><<font color="#0070c0">class </font>T, <font color="#0070c0">typename </font>F></div> <div><span class="Apple-tab-span" style="white-space: pre"> </span><font color="#0070c0">friend </font>IFunctionPtr* CreateFuncPtr(T* object, F function);</div> <div><font color="#0070c0">private</font>:</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>FunctionPtr(T* object, F function)</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>: _obj(object), _func(function) {}</div> <div><br /></div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>T* _obj;</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>F _func;<br />};</div> <div><br /></div> <div><font color="#0070c0">template</font><<font color="#0070c0">class </font>T, <font color="#0070c0">typename </font>F></div>IFunctionPtr* <span style="font-size: 9pt; line-height: 1.5">CreateFuncPtr(T* object, F function)</span> <div><span style="font-size: 9pt; line-height: 1.5">{</span></div> <div><span style="font-size: 9pt; line-height: 1.5"><span class="Apple-tab-span" style="white-space: pre"> </span><font color="#0070c0">return new </font>FunctionPtr<t,f>(object, function);<br />}</t,f></span></div></blockquote><br /></div> <div>사용부분</div> <div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px"><div><font color="#0070c0">class </font>TestFunction</div> <div>{</div> <div><font color="#0070c0">public</font>:</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>TestFunction()<br /><span class="Apple-tab-span" style="white-space: pre"> </span>{</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>m_pFuncPtr = CreateFuncPtr(<font color="#0070c0">this</font>, &TestFunction::CallbackFunction);<br /><span class="Apple-tab-span" style="white-space: pre"> </span>}</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>~TestFunction()<br /><span class="Apple-tab-span" style="white-space: pre"> </span>{</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span><font color="#0070c0">SAFE_DEL(</font>m_pFuncPtr)</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>}</div> <div><br /></div> <div><font color="#0070c0">public</font>:</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span><font color="#0070c0">void operator</font>() () <font color="#0070c0">const</font><br /><span class="Apple-tab-span" style="white-space: pre"> </span>{</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>m_pFuncPtr->Func();</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>}</div> <div><br /></div> <div><span class="Apple-tab-span" style="white-space: pre"> </span><font color="#0070c0">void </font><span style="font-size: 9pt; line-height: 1.5">CallbackFunction()</span></div> <div><span style="font-size: 9pt; line-height: 1.5"><span class="Apple-tab-span" style="white-space: pre"> </span>{</span></div> <div><span style="font-size: 9pt; line-height: 1.5"><span class="Apple-tab-span" style="white-space: pre"> </span>cout << "<font color="#c00000">Callback!!</font>" << endl;<br /><span class="Apple-tab-span" style="white-space: pre"> </span>}</span></div> <div><span style="font-size: 9pt; line-height: 1.5"><br /></span></div> <div><font color="#0070c0">private</font>:</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>IFunctionPtr* m_pFuncPtr;<br />};</div> <div><br /></div> <div><font color="#0070c0">void </font>main()<br />{</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>TestFunction test;</div> <div><span class="Apple-tab-span" style="white-space: pre"> </span>test();<br />}</div></blockquote><br /></div> <div>제가 간단히 만들어본 콜백함수인데요</div> <div><br /></div> <div>아는 정보 공유하고 개선점같은것이 있으면 수정도 해보고파 올려봐요</div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.