class object
{
private:
typedef unsigned int uint_t;
typedef void (object::*object_proc)(uint_t param);
std::map<uint_t, object::object_proc> _lookup_of_object_proc;
public:
uint_t _value;
public:
void initialize (void)
{
_lookup_of_object_proc[0] = &object::test_1;
_lookup_of_object_proc[1] = &object::test_2;
}
void test_1 (uint_t param)
{
printf ("test_1 = %d %d \r\n",_value, param);
}
void test_2 (uint_t param)
{
printf ("test_2 = %d %d \r\n", _value, param);
}
void run (uint_t id, uint_t value)
{
object_proc proc = _lookup_of_object_proc[id];
if (proc)
{
(this->*proc) (value);
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hRes = ::CoInitialize(NULL);
assert(SUCCEEDED(hRes));
object a,b;
a.initialize();
b.initialize();
a._value = 10;
b._value = 20;
a.run (0, 1);
a.run (1, 2);
b.run (0, 1);
b.run (1, 2);
::CoUninitialize();
return 0;
}
---------------------------------------------------------
test_1 = 10 1
test_2 = 10 2
test_1 = 20 1
test_2 = 20 2
계속하려면 아무 키나 누르십시오 . . .