// TestCPPCe.cpp : 응용 프로그램에 대한 진입점을 정의합니다.
//

#include "stdafx.h"
#include "TestCPPCe.h"
#include <tchar.h>
#include <windows.h>
#include <commctrl.h>


////////////////////////////////////////////////////////////////////////
template <typename T>
class RefObjectA
{
public:
 typedef void (T::*ref_object_method_ptr) (void);

 T                     *_ref_object_instance;
 ref_object_method_ptr  _ref_object_method;

public:
 void setInstance (T *instance, ref_object_method_ptr object_method)
 {
  _ref_object_instance = instance;
  _ref_object_method   = object_method;
 }

public:
 void test (void)
 {
  OutputDebugString (_T("===================================================\r\n"));
  OutputDebugString (_T("RefObjectA<T>::test()\r\n"));
  OutputDebugString (_T("===================================================\r\n"));

  (_ref_object_instance->*_ref_object_method) ();

  OutputDebugString (_T("===================================================\r\n"));
  OutputDebugString (_T("\r\n"));
  OutputDebugString (_T("\r\n"));
 }
};
////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////
template <typename T>
class RefObjectB
{
public:
 typedef void (T::*ref_object_method_ptr) (void);

 T                     &_ref_object_instance;
 ref_object_method_ptr  _ref_object_method;

 RefObjectB (T &instance, ref_object_method_ptr object_method);
 void test  (void);
};

template <typename T>
RefObjectB<T>::RefObjectB (T &instance, ref_object_method_ptr object_method) :
 _ref_object_instance  (instance),
 _ref_object_method    (object_method)
{
}

template <typename T>
void RefObjectB<T>::test (void)
{
 OutputDebugString (_T("===================================================\r\n"));
 OutputDebugString (_T("RefObjectB<T>::test()\r\n"));
 OutputDebugString (_T("===================================================\r\n"));

 (_ref_object_instance.*_ref_object_method) ();
 (_ref_object_instance.*_ref_object_method) ();
 (_ref_object_instance.*_ref_object_method) ();

 OutputDebugString (_T("===================================================\r\n"));
 OutputDebugString (_T("\r\n"));
 OutputDebugString (_T("\r\n"));
}
////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////
class Object
{
public:
 RefObjectA <Object> _friend_object1;
 RefObjectB <Object> _friend_object2;
 int                 _test_value;


 void init (void)
 {
  _friend_object1.setInstance (this, &Object::test);  
 }

 Object();
 void test(void);
};

Object::Object () :
 _test_value(0),
 _friend_object2(*this, &Object::test)
{
}

void Object::test (void)
{
 TCHAR message[32];

 _test_value++;
 
 _stprintf (message, _T("Object::test() = %d\r\n"), _test_value);
 OutputDebugString (message);  
}

////////////////////////////////////////////////////////////////////////


int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
 Object obj;

 obj.init ();

 obj._friend_object1.test ();
 obj._friend_object2.test ();


 return 0;
}

----------------------------------------------------------------------


모듈 로드: TestCPPCe.exe
모듈 로드: coredll.dll
===================================================
RefObjectA<T>::test()
===================================================
Object::test() = 1
===================================================


===================================================
RefObjectB<T>::test()
===================================================
Object::test() = 2
Object::test() = 3
Object::test() = 4
===================================================


'[cf56df16] TestCPPCe.exe' 프로그램이 0 (0x0) 코드에서 끝났습니다

Posted by 셈말짓기 :