#include <functional>
#include <vector>
#include <algorithm>
#include <iostream>
typedef std::function<void(int)> Func; class Observer
{
public:
void AddObserver(Func func)
{
m_vecFuncs.push_back(func);
} void Notify(int i)
{
std::for_each(m_vecFuncs.begin(), m_vecFuncs.end(),
[=](Func func){func(i); }
);
} private:
std::vector<Func> m_vecFuncs;
}; class Add
{
public:
void operator()(int i, int b=0)
{
std::cout << i << std::endl;
}
}; class Sub
{
public:
void func(int i)
{
std::cout << i << std::endl;
}
}; int main()
{
Observer observer;
observer.AddObserver(Add()); Sub sub;
observer.AddObserver(std::bind(&Sub::func, &sub, std::placeholders::_1));
observer.Notify(1);
observer.Notify(2);
}