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

上一篇:Python学习笔记12—类


下一篇:java日期int和String互转