#include <vector>
#include <iostream>
#include <algorithm>
typedef int (*MsgProc)();
typedef struct _SWITCH_CASE_
{
int m_value;
MsgProc m_proc;
_SWITCH_CASE_(int value,MsgProc proc)
{
m_value = value;
m_proc = proc;
}
_SWITCH_CASE_(int a)
{
m_value = a;
}
bool operator == (const int value)
{
return (value == m_value);
}
}SWITCHCASE;
std::vector<SWITCHCASE> g_vec;
int DealError()
{
std::cout<<"Deal Error!"<<std::endl;
return 1;
}
int DealSuccess()
{
std::cout<<"Deal Success!"<<std::endl;
return 0;
}
int main(int argc,char * argv[])
{
SWITCHCASE a(0x01,DealError);
SWITCHCASE b(0x00,DealSuccess);
g_vec.push_back(a);
g_vec.push_back(b);
while(1)
{
int a;
std::cin>>a;
int b = 0;
std::vector<SWITCHCASE>::iterator iter = find(g_vec.begin(),g_vec.end(),a);
if(iter != g_vec.end())
{
(*iter).m_proc();
}
else
{
break;
}
}
}
回复 更多评论