The same program as in my previous post, but this time with a functor (overloaded () operator) to make the syntax very easy and C#-like:
#include
#include
using namespace std;
int main();
void myfunc();
void myfunc2();
void myfunc3();
class CDelegator
{
private:
std::vector _functions;
public:
void operator()()
{
Fire();
}
void operator+=(void (fn)())
{
AddFunction(fn);
}
void AddFunctionPtr(void (*fn)())
{
_functions.push_back(fn);
}
void AddFunction(void (fn)())
{
_functions.push_back(*fn);
}
void Fire()
{
vector::iterator iter;
for (iter = _functions.begin();
iter<_functions.end();
iter++)
{
cout << &*iter <>t;
return 0;
}
void myfunc()
{
cout << "MyFunc" << endl;
}
void myfunc2()
{
cout << "MyFunc2" << endl;
}
void myfunc3()
{
cout << "MyFunc3" << endl;
}