#include "stdafx.h"
#include "Event.H"
#include <iostream>
using namespace std;
void ProcArg3(int a,int b,int c)
{
cout<<"Call In ProcArg3."<<endl;
}
void ProcArg2(int a,int b)
{
cout<<"Call In ProcArg2."<<endl;
}
void ProcArgA0()
{
cout<<"Call In ProcArgA0."<<endl;
}
void ProcArgB0()
{
cout<<"Call In ProcArgB0."<<endl;
}
static void ProcArgC0_Static()
{
cout<<"Call In static ProcArgC0_Static."<<endl;
}
class Test
{
private:
void ProcArg1(int )
{
cout<<"Call In Test::ProcArg1."<<endl;
}
void ProcArgA0()
{
cout<<"Call In Test::ProcArgA0."<<endl;
}
void ProcArgB0()
{
cout<<"Call In Test:ProcArgB0."<<endl;
}
static void ProcArgStatic()
{
cout<<"Call In static Test:ProcArgStatic."<<endl;
}
public:
//委托
__Delegate<void,int,int,int> OnArg3Func;
__Delegate<void,int,int> OnArg2Func;
__Delegate<void,int> OnArg1Func;
//事件
__Event<void> OnArg0Func;
Test()
{
OnArg3Func=EventHandler(ProcArg3); //外部函数处理事件
OnArg2Func=EventHandler(ProcArg2); //不同参数的处理
OnArg1Func=EventHandler(this,&Test::ProcArg1); //类成员函数事件处理
//OnArg0Func =EventHandler(::ProcArgA0);
//类的静态方法
OnArg0Func+=EventHandler(Test::ProcArgStatic);
//对象方法
OnArg0Func+=EventHandler(this,&Test::ProcArgA0);
//全局方法
OnArg0Func+=EventHandler(::ProcArgB0);
//全局的静态方法
OnArg0Func+=EventHandler(ProcArgC0_Static);
OnArg0Func+=EventHandler(this,&Test::ProcArgA0);
//演示__Event的 += 操作符
OnArg0Func+=EventHandler(::ProcArgB0);
//演示__Event的 -= 操作符
OnArg0Func-=EventHandler(this,&Test::ProcArgA0);
//OnArg0Func-=EventHandler(this,&Test::ProcArgA0);
OnArg0Func-=EventHandler(::ProcArgA0);
}
void Invoke()
{
OnArg0Func.Invoke();
OnArg1Func.Invoke(0);
OnArg2Func.Invoke(0,0);
OnArg3Func.Invoke(0,0,0) ; //调用事件
}
};
void main()
{
Test *t=new Test;
t->Invoke();
cin.get();
delete t;
}
拒绝显摆。