sigslots的簡單例子

插槽系統常用的有三種:boost的signals,sigslot,sigc++

1、返回值必須爲void
2、Slot參數個數範圍爲0-8個
3、實現slot的類必須繼承自has_slots<>

//////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "sigslot.h"

class Sender     
{   
public:   
    sigslot::signal2< std::string , int > SignalDanger;   
    void SayHelp()   
    {   
   printf("A : ~~ Help~~ \n");
        SignalDanger("Help!", 1);    
    }   
};  


class Receiver : public sigslot::has_slots<>
{
public:
    void OnDanger(std::string message, int time)
    {
        printf("B : I heard something say \"%s\" at %d!\n", message.c_str(), time);
    }
}; 


int main(int argc, char* argv[])
{
Sender sender;
Receiver receiver;
sender.SignalDanger.connect(&receiver, Receiver::OnDanger);
sender.SayHelp();
return 0;
}

//////////////////////////////////////////////////////////////

官網:http://sigslot.sourceforge.net/#intro

0積分下載 vc6實現的一個簡單例子: http://download.csdn.net/detail/moonshine99/4942485

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章