Poco版信号槽

#include "Poco/BasicEvent.h"
#include "Poco/Delegate.h"
#include <iostream>

using Poco::BasicEvent;
using Poco::Delegate;
#include <typeinfo>
class A
{
public:
    BasicEvent<std::string> theEvent;
    void sentToB(std::string message)
    {
        theEvent(this,message);
    }
    void getFromB(const void* pSender,std::string &message)
    {
        std::cout<<"cur class is:"<<typeid(A).name()<<std::endl;
        std::cout<<"B says:"<<message<<std::endl;
    }
};
class B
{
public:
    BasicEvent<std::string> theEvent;
    void sentToA(std::string message)
    {
        theEvent(this,message);
    }
    void getFromA(const void* pSender,std::string &message)
    {
        std::cout<<"cur class is:"<<typeid(B).name()<<std::endl;
        std::cout<<"A says:"<<message<<std::endl;
    }
};
int main(int argc,char ** argv)
{
    A aDemo;
    B bDemo;

    aDemo.theEvent += Delegate<B,std::string>(&bDemo,&B::getFromA);
    bDemo.theEvent += Delegate<A,std::string>(&aDemo,&A::getFromB);

    aDemo.sentToB("bendan");
    bDemo.sentToA("zhen sha");
    return 0;
}
-lPocoFoundation

生活的残酷,让我们习惯了忘记疲倦,一直奔向远方,追寻着自己的梦想。
原文地址:https://www.cnblogs.com/L-Arikes/p/4969422.html